new vers
This commit is contained in:
@@ -11,7 +11,7 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
string Title { get;}
|
||||
DateTime DateIssue { get;}
|
||||
DateTime DateDelivery { get;}
|
||||
int TeacherID { get; }
|
||||
int TeacherId { get; }
|
||||
Dictionary<int, IMaterial> TaskMaterials { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public int TeacherID { get; set; }
|
||||
public int TeacherId { get; set; }
|
||||
|
||||
public Dictionary<int, IMaterial> TaskMaterials { get; set; } = new();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
[DisplayName("Дата сдачи")]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public int TeacherID { get; set; }
|
||||
public int TeacherId { get; set; }
|
||||
|
||||
public Dictionary<int, IMaterial> TaskMaterials { get; set; } = new();
|
||||
[DisplayName("Номер")]
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
[Required]
|
||||
public int TaskId { get; set; }
|
||||
public string TaskName { get; set; } = string.Empty;
|
||||
public virtual Task task { get; set; }
|
||||
public int StudentId { get; set; }
|
||||
private Dictionary<int, IInterest>? _DiyInterests = null;
|
||||
[NotMapped]
|
||||
@@ -46,9 +47,9 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
return new Diy()
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
Description = model.Description,
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
Description = model.Description,
|
||||
DateCreate = model.DateCreate,
|
||||
TaskId = model.TaskId,
|
||||
TaskName = model.TaskName,
|
||||
@@ -64,6 +65,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Title = model.Title;
|
||||
Description = model.Description;
|
||||
DateCreate = model.DateCreate;
|
||||
}
|
||||
|
||||
public DiyViewModel GetViewModel => new()
|
||||
|
||||
106
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Lesson.cs
Normal file
106
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Lesson.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using SchoolAgainStudyContracts.BindingModel;
|
||||
using SchoolAgainStudyContracts.ViewModel;
|
||||
using SchoolAgainStudyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class Lesson : ILesson
|
||||
{
|
||||
[Required]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime DateEvent { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
public virtual Product product { get; set; }
|
||||
public int TeacherId { get; set; }
|
||||
private Dictionary<int, IMaterial>? _LessonMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> LessonMaterials
|
||||
{ get
|
||||
{
|
||||
if (_LessonMaterials == null)
|
||||
{
|
||||
_LessonMaterials = Materials
|
||||
.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterial));
|
||||
}
|
||||
return _LessonMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("LessonId")]
|
||||
public virtual List<LessonMaterial> Materials { get; set; } = new();
|
||||
public static Lesson Create(SchoolDataBase context, LessonBindingModel model)
|
||||
{
|
||||
return new Lesson()
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
DateEvent = model.DateEvent,
|
||||
ProductId = model.ProductId,
|
||||
ProductName = model.ProductName,
|
||||
TeacherId = model.TeacherId,
|
||||
Materials = model.LessonMaterials.Select(x => new LessonMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(LessonBindingModel model)
|
||||
{
|
||||
Title = model.Title;
|
||||
DateEvent = model.DateEvent;
|
||||
}
|
||||
|
||||
public LessonViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Title = Title,
|
||||
DateEvent = DateEvent,
|
||||
ProductId = ProductId,
|
||||
ProductName = ProductName,
|
||||
TeacherId = TeacherId,
|
||||
LessonMaterials = LessonMaterials
|
||||
};
|
||||
|
||||
public void UpdateMaterials(SchoolDataBase context, LessonBindingModel model)
|
||||
{
|
||||
var lessonMaterials = context.LessonMaterials.Where(rec => rec.LessonId == model.Id).ToList();
|
||||
if (lessonMaterials != null && lessonMaterials.Count > 0)
|
||||
{
|
||||
context.LessonMaterials.RemoveRange(lessonMaterials.Where(rec => !model.LessonMaterials.ContainsKey(rec.MaterialId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateMaterial in lessonMaterials)
|
||||
{
|
||||
model.LessonMaterials.Remove(updateMaterial.MaterialId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var lesson = context.Lessons.First(x => x.Id == Id);
|
||||
foreach (var pc in model.LessonMaterials)
|
||||
{
|
||||
context.LessonMaterials.Add(new LessonMaterial
|
||||
{
|
||||
Lesson = lesson,
|
||||
Material = context.Materials.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_LessonMaterials = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class LessonMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int LessonId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
public virtual Lesson Lesson { get; set; } = new();
|
||||
public virtual Material Material { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using SchoolAgainStudyContracts.BindingModel;
|
||||
using SchoolAgainStudyContracts.ViewModel;
|
||||
using SchoolAgainStudyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class Material : IMaterial
|
||||
{
|
||||
[Required]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string SphereUse { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<LessonMaterial> LessonMaterials { get; set; } = new();
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<TaskMaterial> TaskMaterial { get; set; } = new();
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<TeacherMaterial> TeacherMaterial { get; set; } = new();
|
||||
|
||||
public static Material? Create(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Material()
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
SphereUse = model.SphereUse
|
||||
};
|
||||
}
|
||||
|
||||
public static Material Create(MaterialViewModel model)
|
||||
{
|
||||
return new Material
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
SphereUse = model.SphereUse
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Title = model.Title;
|
||||
SphereUse = model.SphereUse;
|
||||
}
|
||||
|
||||
public MaterialViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Title = Title,
|
||||
SphereUse = SphereUse
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Title = model.Title;
|
||||
Description = model.Description;
|
||||
DateCreate = model.DateCreate;
|
||||
}
|
||||
|
||||
public ProductViewModel GetViewModel => new()
|
||||
|
||||
103
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Task.cs
Normal file
103
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Task.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using SchoolAgainStudyContracts.BindingModel;
|
||||
using SchoolAgainStudyContracts.ViewModel;
|
||||
using SchoolAgainStudyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class Task : ITask
|
||||
{
|
||||
[Required]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime DateIssue { get; set; }
|
||||
[Required]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public int TeacherId { get; set; }
|
||||
private Dictionary<int, IMaterial>? _TaskMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> TaskMaterials { get
|
||||
{
|
||||
if (_TaskMaterials == null)
|
||||
{
|
||||
_TaskMaterials = Materials
|
||||
.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterial));
|
||||
}
|
||||
return _TaskMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("TaskId")]
|
||||
public virtual List<TaskMaterial> Materials { get; set; } = new();
|
||||
[ForeignKey("TaskId")]
|
||||
public virtual List<Diy> Diys { get; set; } = new();
|
||||
|
||||
public static Task Create(SchoolDataBase context, TaskBindingModel model)
|
||||
{
|
||||
return new Task()
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
DateIssue = model.DateIssue,
|
||||
DateDelivery = model.DateDelivery,
|
||||
TeacherId = model.TeacherId,
|
||||
Materials = model.TaskMaterials.Select(x => new TaskMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TaskBindingModel model)
|
||||
{
|
||||
Title = model.Title;
|
||||
DateIssue = model.DateIssue;
|
||||
DateDelivery = model.DateDelivery;
|
||||
}
|
||||
|
||||
public TaskViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Title = Title,
|
||||
DateIssue = DateIssue,
|
||||
DateDelivery = DateDelivery,
|
||||
TeacherId = TeacherId,
|
||||
TaskMaterials = TaskMaterials
|
||||
};
|
||||
|
||||
public void UpdateMaterials(SchoolDataBase context, TaskBindingModel model)
|
||||
{
|
||||
var taskMaterials = context.TaskMaterials.Where(rec => rec.TaskId == model.Id).ToList();
|
||||
if (taskMaterials != null && taskMaterials.Count > 0)
|
||||
{
|
||||
context.TaskMaterials.RemoveRange(taskMaterials.Where(rec => !model.TaskMaterials.ContainsKey(rec.MaterialId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateMaterial in taskMaterials)
|
||||
{
|
||||
model.TaskMaterials.Remove(updateMaterial.MaterialId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var task = context.Tasks.First(x => x.Id == Id);
|
||||
foreach (var pc in model.TaskMaterials)
|
||||
{
|
||||
context.TaskMaterials.Add(new TaskMaterial
|
||||
{
|
||||
Task = task,
|
||||
Material = context.Materials.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_TaskMaterials = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class TaskMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int TaskId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
public virtual Task Task { get; set; } = new();
|
||||
public virtual Material Material { get; set; } = new();
|
||||
}
|
||||
}
|
||||
112
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Teacher.cs
Normal file
112
ProtRPP/SchoolAgainStudyDataBaseImplements/Models/Teacher.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using SchoolAgainStudyContracts.BindingModel;
|
||||
using SchoolAgainStudyContracts.ViewModel;
|
||||
using SchoolAgainStudyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class Teacher : ITeacher
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Post { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
private Dictionary<int, IMaterial>? _TeacherMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> TeacherMaterials {
|
||||
get
|
||||
{
|
||||
if (_TeacherMaterials == null)
|
||||
{
|
||||
_TeacherMaterials = Materials
|
||||
.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterial));
|
||||
}
|
||||
return _TeacherMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("TeacherId")]
|
||||
public virtual List<TeacherMaterial> Materials { get; set; } = new();
|
||||
[ForeignKey("TeacherId")]
|
||||
public virtual List<Task> Tasks { get; set; } = new();
|
||||
[ForeignKey("TeacherId")]
|
||||
public virtual List<Lesson> Lessons { get; set; } = new();
|
||||
public static Teacher Create(SchoolDataBase context, TeacherBindingModel model)
|
||||
{
|
||||
return new Teacher()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Post = model.Post,
|
||||
Phone = model.Phone,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
Materials = model.TeacherMaterials.Select(x => new TeacherMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TeacherBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Post = model.Post;
|
||||
Phone = model.Phone;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public TeacherViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Post = Post,
|
||||
Phone = Phone,
|
||||
Login = Login,
|
||||
Password = Password,
|
||||
TeacherMaterials = TeacherMaterials
|
||||
};
|
||||
|
||||
public void UpdateMaterials(SchoolDataBase context, TeacherBindingModel model)
|
||||
{
|
||||
var teacherMaterials = context.TeacherMaterials.Where(rec => rec.TeacherId == model.Id).ToList();
|
||||
if (teacherMaterials != null && teacherMaterials.Count > 0)
|
||||
{
|
||||
context.TeacherMaterials.RemoveRange(teacherMaterials.Where(rec => !model.TeacherMaterials.ContainsKey(rec.MaterialId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateMaterial in teacherMaterials)
|
||||
{
|
||||
model.TeacherMaterials.Remove(updateMaterial.MaterialId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var teacher = context.Teachers.First(x => x.Id == Id);
|
||||
foreach (var pc in model.TeacherMaterials)
|
||||
{
|
||||
context.TeacherMaterials.Add(new TeacherMaterial
|
||||
{
|
||||
Teacher = teacher,
|
||||
Material = context.Materials.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_TeacherMaterials = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class TeacherMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int TeacherId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
public virtual Teacher Teacher { get; set; } = new();
|
||||
public virtual Material Material { get; set; } = new();
|
||||
}
|
||||
}
|
||||
48
ProtRPP/SchoolAgainStudyDataBaseImplements/SchoolDataBase.cs
Normal file
48
ProtRPP/SchoolAgainStudyDataBaseImplements/SchoolDataBase.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SchoolAgainStudyDataBaseImplements.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Task = SchoolAgainStudyDataBaseImplements.Models.Task;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements
|
||||
{
|
||||
public class SchoolDataBase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Server=PostgreSQL;Host=localhost;Port=5432;Database=AutoPlantDB;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Student> Students { set; get; }
|
||||
|
||||
public virtual DbSet<StudentInterest> StudentInterests { set; get; }
|
||||
|
||||
public virtual DbSet<Interest> Interests { set; get; }
|
||||
|
||||
public virtual DbSet<Diy> Diys { set; get; }
|
||||
public virtual DbSet<DiyInterest> DiyInterests { set; get; }
|
||||
public virtual DbSet<Product> Products { set; get; }
|
||||
public virtual DbSet<ProductInterest> ProductInterests { set; get; }
|
||||
|
||||
public virtual DbSet<Teacher> Teachers { set; get; }
|
||||
|
||||
public virtual DbSet<TeacherMaterial> TeacherMaterials { set; get; }
|
||||
|
||||
public virtual DbSet<Material> Materials { set; get; }
|
||||
|
||||
public virtual DbSet<Lesson> Lessons { set; get; }
|
||||
public virtual DbSet<LessonMaterial> LessonMaterials { set; get; }
|
||||
public virtual DbSet<Task> Tasks { set; get; }
|
||||
public virtual DbSet<TaskMaterial> TaskMaterials { set; get; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user