Готовые модели бд + продолжение бизнес логики
This commit is contained in:
parent
e1482243ed
commit
93f012e03b
@ -12,7 +12,7 @@ using UniversityContracts.ViewModels;
|
|||||||
using UniversityDataModels.Enums;
|
using UniversityDataModels.Enums;
|
||||||
|
|
||||||
namespace UniversityBusinessLogic.BusinessLogics
|
namespace UniversityBusinessLogic.BusinessLogics
|
||||||
{/*
|
{
|
||||||
public class AttestationLogic : IAttestationLogic
|
public class AttestationLogic : IAttestationLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
@ -25,8 +25,8 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
public List<AttestationViewModel>? ReadList(AttestationSearchModel? model)
|
public List<AttestationViewModel>? ReadList(AttestationSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. FormOfEvaluation: {FormOfEvaluation}.Id:{Id} ",
|
_logger.LogInformation("ReadList.AttestationId:{Id} ",
|
||||||
model?.FormOfEvaluation, model?.Id);
|
model?.Id);
|
||||||
var list = model == null ? _attestationStorage.GetFullList() :
|
var list = model == null ? _attestationStorage.GetFullList() :
|
||||||
_attestationStorage.GetFilteredList(model);
|
_attestationStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
@ -43,8 +43,8 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement. FormOfEvaluation:{FormOfEvaluation}.Id:{Id}",
|
_logger.LogInformation("ReadElement.Id:{Id}",
|
||||||
model.FormOfEvaluation, model.Id);
|
model.Id);
|
||||||
var element = _attestationStorage.GetElement(model);
|
var element = _attestationStorage.GetElement(model);
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
public bool Create(AttestationBindingModel model)
|
public bool CreateAttestation(AttestationBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool StatusUpdate(AttestationBindingModel model, AttestationScore newScore)
|
public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (model.Score + 1 != newScore)
|
if (model.Score + 1 != newScore)
|
||||||
@ -132,5 +132,5 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
|
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityDataModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class WorkerBindingModel : IWorkerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string FirstName { get; set; } = string.Empty;
|
||||||
|
public string LastName { get; set; } = string.Empty;
|
||||||
|
public string MiddleName { get; set; } = string.Empty;
|
||||||
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -12,9 +12,13 @@ namespace UniversityContracts.BusinessLogicsContracts
|
|||||||
public interface IAttestationLogic
|
public interface IAttestationLogic
|
||||||
{
|
{
|
||||||
List<AttestationViewModel>? ReadList(AttestationSearchModel? model);
|
List<AttestationViewModel>? ReadList(AttestationSearchModel? model);
|
||||||
AttestationViewModel? ReadElement(AttestationSearchModel model);
|
bool CreateAttestation(AttestationBindingModel model);
|
||||||
bool Create(AttestationBindingModel model);
|
bool SetPass(AttestationBindingModel model);
|
||||||
bool Update(AttestationBindingModel model);
|
bool SetNotPass(AttestationBindingModel model);
|
||||||
bool Delete(AttestationBindingModel model);
|
bool Set(AttestationBindingModel model);
|
||||||
|
bool Set(AttestationBindingModel model);
|
||||||
|
bool Set(AttestationBindingModel model);
|
||||||
|
bool SetNotCredit(AttestationBindingModel model);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace UniversityContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerLogic
|
||||||
|
{
|
||||||
|
List<WorkerViewModel>? ReadList(WorkerSearchModel? model);
|
||||||
|
WorkerViewModel? ReadElement(WorkerSearchModel model);
|
||||||
|
bool Create(WorkerBindingModel model);
|
||||||
|
bool Update(WorkerBindingModel model);
|
||||||
|
bool Delete(WorkerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace UniversityContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class WorkerSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? FirstName { get; set; }
|
||||||
|
public string? LastName { get; set; }
|
||||||
|
public string? MiddleName { get; set; }
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
public string? Email { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace UniversityContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerStorage
|
||||||
|
{
|
||||||
|
List<WorkerViewModel> GetFullList();
|
||||||
|
List<WorkerViewModel> GetFilteredList(WorkerSearchModel model);
|
||||||
|
WorkerViewModel? GetElement(WorkerSearchModel model);
|
||||||
|
WorkerViewModel? Insert(WorkerBindingModel model);
|
||||||
|
WorkerViewModel? Update(WorkerBindingModel model);
|
||||||
|
WorkerViewModel? Delete(WorkerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
25
University/UniversityContracts/ViewModels/WorkerViewModel.cs
Normal file
25
University/UniversityContracts/ViewModels/WorkerViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityDataModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class WorkerViewModel : IWorkerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
|
public string FirstName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
|
public string LastName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Отчество")]
|
||||||
|
public string MiddleName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Номер телефона")]
|
||||||
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Почта")]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.StorageContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace UniversityDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class WorkerStorage : IWorkerStorage
|
||||||
|
{
|
||||||
|
public WorkerViewModel? GetElement(WorkerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
|
||||||
|
return context.Workers.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email)
|
||||||
|
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkerViewModel> GetFilteredList(WorkerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
return context.Workers
|
||||||
|
.Where(x => x.Email.Contains(model.Email))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WorkerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
return context.Workers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkerViewModel? Insert(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
var newWorker = Worker.Create(model);
|
||||||
|
if (newWorker == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
context.Workers.Add(newWorker);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newWorker.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkerViewModel? Update(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var client = context.Workers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
client.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
public WorkerViewModel? Delete(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var client = context.Workers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Workers.Remove(client);
|
||||||
|
context.SaveChanges();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,6 +35,8 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
[ForeignKey("PlanOfStudyId")]
|
[ForeignKey("PlanOfStudyId")]
|
||||||
public virtual List<PlanOfStudyTeacher> Teachers { get; set; } = new();
|
public virtual List<PlanOfStudyTeacher> Teachers { get; set; } = new();
|
||||||
|
[ForeignKey("PlanOfStudyId")]
|
||||||
|
public virtual List<Student> Students { get; set; } = new();
|
||||||
public virtual Worker Worker { get; set; } = new();
|
public virtual Worker Worker { get; set; } = new();
|
||||||
public static PlanOfStudy Create(UniversityDatabase context, PlanOfStudyBindingModel model)
|
public static PlanOfStudy Create(UniversityDatabase context, PlanOfStudyBindingModel model)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,8 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
public string PhoneNumber { get; private set; } = string.Empty;
|
public string PhoneNumber { get; private set; } = string.Empty;
|
||||||
[ForeignKey("StudentId")]
|
[ForeignKey("StudentId")]
|
||||||
public virtual List<StudentDiscipline> StudentDiscipline { get; set; } = new();
|
public virtual List<StudentDiscipline> StudentDiscipline { get; set; } = new();
|
||||||
|
[ForeignKey("StudentId")]
|
||||||
|
public virtual List<Attestation> Attestations { get; set; } = new();
|
||||||
public virtual PlanOfStudy PlanOfStudy { get; set; } = new();
|
public virtual PlanOfStudy PlanOfStudy { get; set; } = new();
|
||||||
public static Student? Create(StudentBindingModel model)
|
public static Student? Create(StudentBindingModel model)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
public virtual List<Statement> Statements { get; set; } = new();
|
public virtual List<Statement> Statements { get; set; } = new();
|
||||||
[ForeignKey("TeacherId")]
|
[ForeignKey("TeacherId")]
|
||||||
public virtual List<Discipline> Disciplines { get; set; } = new();
|
public virtual List<Discipline> Disciplines { get; set; } = new();
|
||||||
|
[ForeignKey("TeacherId")]
|
||||||
public virtual List<PlanOfStudyTeacher> PlanOfStudyTeachers { get; set; } = new();
|
public virtual List<PlanOfStudyTeacher> PlanOfStudyTeachers { get; set; } = new();
|
||||||
public static Teacher? Create(TeacherBindingModel model)
|
public static Teacher? Create(TeacherBindingModel model)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,81 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
using UniversityDataModels.Models;
|
using UniversityDataModels.Models;
|
||||||
|
|
||||||
namespace UniversityDatabaseImplement.Models
|
namespace UniversityDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Worker : IWorkerModel
|
public class Worker : IWorkerModel
|
||||||
{
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string FirstName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string LastName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string MiddleName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string PhoneNumber { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Email { get; private set; } = string.Empty;
|
||||||
|
[ForeignKey("WorkerId")]
|
||||||
|
public virtual List<PlanOfStudy> PlanOfStudys { get; set; } = new();
|
||||||
|
public static Worker? Create(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Worker()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FirstName = model.FirstName,
|
||||||
|
LastName = model.LastName,
|
||||||
|
MiddleName = model.MiddleName,
|
||||||
|
PhoneNumber = model.PhoneNumber,
|
||||||
|
Email = model.Email,
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Worker Create(WorkerViewModel model)
|
||||||
|
{
|
||||||
|
return new Worker
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
FirstName = model.FirstName,
|
||||||
|
LastName = model.LastName,
|
||||||
|
MiddleName = model.MiddleName,
|
||||||
|
PhoneNumber = model.PhoneNumber,
|
||||||
|
Email = model.Email,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
FirstName = model.FirstName;
|
||||||
|
LastName = model.LastName;
|
||||||
|
MiddleName = model.MiddleName;
|
||||||
|
PhoneNumber = model.PhoneNumber;
|
||||||
|
Email = model.Email;
|
||||||
|
}
|
||||||
|
public WorkerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
FirstName = FirstName,
|
||||||
|
LastName = LastName,
|
||||||
|
MiddleName = MiddleName,
|
||||||
|
PhoneNumber = PhoneNumber,
|
||||||
|
Email = Email,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace UniversityDatabaseImplement
|
|||||||
public virtual DbSet<Student> Students { set; get; }
|
public virtual DbSet<Student> Students { set; get; }
|
||||||
public virtual DbSet<PlanOfStudy> PlanOfStudys { set; get; }
|
public virtual DbSet<PlanOfStudy> PlanOfStudys { set; get; }
|
||||||
public virtual DbSet<Attestation> Attestations { set; get; }
|
public virtual DbSet<Attestation> Attestations { set; get; }
|
||||||
// public virtual DbSet<Worker> Workers { set; get; }
|
public virtual DbSet<Worker> Workers { set; get; }
|
||||||
public virtual DbSet<Storekeeper> Storekeepers { set; get; }
|
public virtual DbSet<Storekeeper> Storekeepers { set; get; }
|
||||||
public virtual DbSet<Teacher> Teachers { set; get; }
|
public virtual DbSet<Teacher> Teachers { set; get; }
|
||||||
public virtual DbSet<Discipline> Disciplines { set; get; }
|
public virtual DbSet<Discipline> Disciplines { set; get; }
|
||||||
|
Loading…
Reference in New Issue
Block a user