Compare commits

...

11 Commits

28 changed files with 555 additions and 173 deletions

View File

@ -8,30 +8,11 @@ namespace UniversityDatabaseImplement.Implements
{
internal class ActivityStorage : IActivityStorage
{
public ActivityViewModel? Delete(ActivityBindingModel model)
public List<ActivityViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.Activities.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Activities.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
return context.Activities.Select(x => x.GetViewModel).ToList();
}
public ActivityViewModel? GetElement(ActivitySearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Activities
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ActivityViewModel> GetFilteredList(ActivitySearchModel model)
{
using var context = new UniversityDatabase();
@ -43,13 +24,16 @@ namespace UniversityDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<ActivityViewModel> GetFullList()
public ActivityViewModel? GetElement(ActivitySearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Activities.Select(x => x.GetViewModel).ToList();
return context.Activities
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ActivityViewModel? Insert(ActivityBindingModel model)
{
var newActivity = Activity.Create(model);
@ -75,5 +59,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return activity.GetViewModel;
}
public ActivityViewModel? Delete(ActivityBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Activities.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Activities.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -8,31 +8,11 @@ namespace UniversityDatabaseImplement.Implements
{
internal class DisciplineStorage : IDisciplineStorage
{
public DisciplineViewModel? Delete(DisciplineBindingModel model)
public List<DisciplineViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ExaminationResults.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
return context.Disciplines.Select(x => x.GetViewModel).ToList();
}
public DisciplineViewModel? GetElement(DisciplineSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Disciplines
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<DisciplineViewModel> GetFilteredList(DisciplineSearchModel model)
{
using var context = new UniversityDatabase();
@ -45,13 +25,17 @@ namespace UniversityDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<DisciplineViewModel> GetFullList()
public DisciplineViewModel? GetElement(DisciplineSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Disciplines.Select(x => x.GetViewModel).ToList();
return context.Disciplines
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public DisciplineViewModel? Insert(DisciplineBindingModel model)
{
var newDiscipline = Discipline.Create(model);
@ -64,7 +48,6 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return newDiscipline.GetViewModel;
}
public DisciplineViewModel? Update(DisciplineBindingModel model)
{
using var context = new UniversityDatabase();
@ -77,5 +60,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return discipline.GetViewModel;
}
public DisciplineViewModel? Delete(DisciplineBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Disciplines.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -8,30 +8,11 @@ namespace UniversityDatabaseImplement.Implements
{
internal class ExaminationResultStorage : IExaminationResultStorage
{
public ExaminationResultViewModel? Delete(ExaminationResultBindingModel model)
public List<ExaminationResultViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.ExaminationResults.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ExaminationResults.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
return context.ExaminationResults.Select(x => x.GetViewModel).ToList();
}
public ExaminationResultViewModel? GetElement(ExaminationResultSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ExaminationResults
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ExaminationResultViewModel> GetFilteredList(ExaminationResultSearchModel model)
{
using var context = new UniversityDatabase();
@ -43,13 +24,16 @@ namespace UniversityDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<ExaminationResultViewModel> GetFullList()
public ExaminationResultViewModel? GetElement(ExaminationResultSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ExaminationResults.Select(x => x.GetViewModel).ToList();
return context.ExaminationResults
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ExaminationResultViewModel? Insert(ExaminationResultBindingModel model)
{
var newExaminationResult = ExaminationResult.Create(model);
@ -75,5 +59,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return examinationResult.GetViewModel;
}
public ExaminationResultViewModel? Delete(ExaminationResultBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.ExaminationResults.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ExaminationResults.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -8,31 +8,11 @@ namespace UniversityDatabaseImplement.Implements
{
internal class ReportTypeStorage : IReportTypeStorage
{
public ReportTypeViewModel? Delete(ReportTypeBindingModel model)
public List<ReportTypeViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.ReportTypes.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ReportTypes.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
return context.ReportTypes.Select(x => x.GetViewModel).ToList();
}
public ReportTypeViewModel? GetElement(ReportTypeSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ReportTypes
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ReportTypeViewModel> GetFilteredList(ReportTypeSearchModel model)
{
using var context = new UniversityDatabase();
@ -45,13 +25,17 @@ namespace UniversityDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<ReportTypeViewModel> GetFullList()
public ReportTypeViewModel? GetElement(ReportTypeSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ReportTypes.Select(x => x.GetViewModel).ToList();
return context.ReportTypes
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ReportTypeViewModel? Insert(ReportTypeBindingModel model)
{
var newReportType = ReportType.Create(model);
@ -77,5 +61,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return reportType.GetViewModel;
}
public ReportTypeViewModel? Delete(ReportTypeBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.ReportTypes.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ReportTypes.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -3,24 +3,34 @@ using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class StatementStorage : IStatementStorage
{
public StatementViewModel? Delete(StatementBindingModel model)
public List<StatementViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Statements.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
return context.Statements
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Student)
.Select(x => x.GetViewModel)
.ToList();
}
public List<StatementViewModel> GetFilteredList(StatementSearchModel model)
{
using var context = new UniversityDatabase();
return context.Statements
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Student)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id)
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public StatementViewModel? GetElement(StatementSearchModel model)
{
if (!model.Id.HasValue)
@ -29,27 +39,10 @@ namespace UniversityDatabaseImplement.Implements
}
using var context = new UniversityDatabase();
return context.Statements
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Student)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<StatementViewModel> GetFilteredList(StatementSearchModel model)
{
using var context = new UniversityDatabase();
return context.Statements
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id)
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public List<StatementViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Statements.Select(x => x.GetViewModel).ToList();
}
public StatementViewModel? Insert(StatementBindingModel model)
{
var newStatement = Statement.Create(model);
@ -75,5 +68,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return statement.GetViewModel;
}
public StatementViewModel? Delete(StatementBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Statements.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -3,40 +3,27 @@ using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class StudentStorage : IStudentStorage
{
public StudentViewModel? Delete(StudentBindingModel model)
public List<StudentViewModel> GetFullList()
{
using var context = new UniversityDatabase();
var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Students.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Students
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.ExaminationResult)
.Select(x => x.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{
using var context = new UniversityDatabase();
return context.Students
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.ExaminationResult)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
@ -45,13 +32,19 @@ namespace UniversityDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetFullList()
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Students.Select(x => x.GetViewModel).ToList();
return context.Students
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.ExaminationResult)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public StudentViewModel? Insert(StudentBindingModel model)
{
var newStudent = Student.Create(model);
@ -77,5 +70,17 @@ namespace UniversityDatabaseImplement.Implements
context.SaveChanges();
return student.GetViewModel;
}
public StudentViewModel? Delete(StudentBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Students.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,78 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement.Implements
{
internal class UserStorage : IUserStorage
{
public List<UserViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Users.Select(x => x.GetViewModel).ToList();
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
using var context = new UniversityDatabase();
return context.Users
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Login) || x.Login.Contains(model.Login)) &&
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public UserViewModel? GetElement(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Users
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(!string.IsNullOrEmpty(model.Password) && x.Password == model.Password) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public UserViewModel? Insert(UserBindingModel model)
{
var newUser = User.Create(model);
if (newUser == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Users.Add(newUser);
context.SaveChanges();
return newUser.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new UniversityDatabase();
var user = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (user == null)
{
return null;
}
user.Update(model);
context.SaveChanges();
return user.GetViewModel;
}
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -10,9 +10,9 @@ namespace UniversityDatabaseImplement.Models
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
[Required]
public string Department { get; set; }
public string Department { get; set; } = string.Empty;
[ForeignKey("DisciplineId")]
public virtual List<Statement> Statements { get; set; } = new();
[ForeignKey("DisciplineId")]

View File

@ -10,7 +10,7 @@ namespace UniversityDatabaseImplement.Models
public class ExaminationResult : IExaminationResultModel
{
public int Id { get; set; }
public string ExaminationForm { get; set; }
public string ExaminationForm { get; set; } = string.Empty;
[Required]
public MarkType Mark { get; set; }
[Required]

View File

@ -10,7 +10,7 @@ namespace UniversityDatabaseImplement.Models
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
[ForeignKey("ReportTypeId")]
public virtual List<ReportTypeActivity> ReportTypeActivities { get; set; } = new();
[ForeignKey("ReportTypeId")]

View File

@ -17,6 +17,20 @@ namespace UniversityDatabaseImplement.Models
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
[ForeignKey("StatementId")]
public virtual List<ExaminationResult> ExaminationResults { get; set; } = new();
private Dictionary<int, IStudentModel>? _students = null;
public Dictionary<int, IStudentModel> Students
{
get
{
if(_students == null)
{
_students = StatementStudents.ToDictionary(
x => x.Student.Id, x => x.Student as IStudentModel);
}
return _students;
}
}
public static Statement Create(StatementBindingModel model)
{
return new Statement
@ -39,7 +53,9 @@ namespace UniversityDatabaseImplement.Models
{
Id = Id,
Date = Date,
HoursCount = HoursCount
HoursCount = HoursCount,
Students = Students
};
}
}

View File

@ -10,13 +10,27 @@ namespace UniversityDatabaseImplement.Models
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
[Required]
public string RecordCardNumber { get; set; }
public string RecordCardNumber { get; set; } = string.Empty;
[ForeignKey("StudentId")]
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
private Dictionary<int, IExaminationResultModel>? _results;
[NotMapped]
public Dictionary<int, IExaminationResultModel> Results {
get {
if(_results == null)
{
_results = StudentExaminationResults.ToDictionary(
x => x.ExaminationResult.Id, x => x.ExaminationResult as IExaminationResultModel);
}
return _results;
}
}
public static Student Create(StudentBindingModel model)
{
return new Student
@ -39,7 +53,9 @@ namespace UniversityDatabaseImplement.Models
{
Id = Id,
Name = Name,
RecordCardNumber = RecordCardNumber
RecordCardNumber = RecordCardNumber,
Results = Results
};
}
}

View File

@ -0,0 +1,62 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class User : IUserModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
[Required]
public string Position { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
public static User Create(UserBindingModel model)
{
return new User
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
PhoneNumber = model.PhoneNumber,
Position = model.Position,
Login = model.Login,
Password = model.Password
};
}
public void Update(UserBindingModel model)
{
if (model == null) return;
Id = model.Id;
Name = model.Name;
Surname = model.Surname;
PhoneNumber = model.PhoneNumber;
Position = model.Position;
Login = model.Login;
Password = model.Password;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
PhoneNumber = PhoneNumber,
Position = Position,
Login = Login,
Password = Password
};
}
}

View File

@ -23,5 +23,6 @@ namespace UniversityDatabaseImplement
public virtual DbSet<StatementStudent> StatementStudents { set; get; }
public virtual DbSet<Student> Students { set; get; }
public virtual DbSet<StudentExaminationResult> StudentExaminationResults { set; get; }
public virtual DbSet<User> Users { set; get; }
}
}

View File

@ -0,0 +1,130 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic
{
public class UserLogic : IUserLogic
{
private readonly ILogger _logger;
private readonly IUserStorage _userStorage;
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage)
{
_logger = logger;
_userStorage = userStorage;
}
public bool Create(UserBindingModel model)
{
CheckModel(model);
if (_userStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(UserBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_userStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public UserViewModel? ReadElement(UserSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _userStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<UserViewModel>? ReadList(UserSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(UserBindingModel model)
{
CheckModel(model);
if (_userStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(UserBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Surname))
{
throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name));
}
else if (model.Password.Length < 6)
{
throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name));
}
_logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " +
"Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id);
var element = _userStorage.GetElement(new UserSearchModel
{
Login = model.Login,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Пользователь с таким логином уже есть");
}
}
}
}

View File

@ -7,5 +7,6 @@ namespace UniversityContracts.BindingModels
public int Id { get; set; }
public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
public int HoursCount { get; set; }
public Dictionary<int, IStudentModel> Students { get; set; } = new();
}
}

View File

@ -7,5 +7,6 @@ namespace UniversityContracts.BindingModels
public int Id { get; set; }
public string Name { get; set; } = String.Empty;
public string RecordCardNumber { get; set; } = String.Empty;
public Dictionary<int, IExaminationResultModel> Results { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using UniversityDataModels.Models;
namespace UniversityContracts.BindingModels
{
public class UserBindingModel : IUserModel
{
public int Id { get; set; }
public string Name { get; set; } = String.Empty;
public string Surname { get; set; } = String.Empty;
public string PhoneNumber { get; set; } = String.Empty;
public string Position { get; set; } = String.Empty;
public string Login { get; set; } = String.Empty;
public string Password { get; set; } = String.Empty;
}
}

View File

@ -0,0 +1,15 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
namespace UniversityContracts.BuisnessLogicContracts
{
public interface IUserLogic
{
List<UserViewModel>? ReadList(UserSearchModel? model);
UserViewModel? ReadElement(UserSearchModel model);
bool Create(UserBindingModel model);
bool Update(UserBindingModel model);
bool Delete(UserBindingModel model);
}
}

View File

@ -0,0 +1,9 @@
namespace UniversityContracts.SearchModels
{
public class UserSearchModel
{
public int? Id { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
namespace UniversityContracts.StoragesContracts
{
public interface IUserStorage
{
List<UserViewModel> GetFullList();
List<UserViewModel> GetFilteredList(UserSearchModel model);
UserViewModel? GetElement(UserSearchModel model);
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
}
}

View File

@ -7,5 +7,6 @@ namespace UniversityContracts.ViewModels
public int Id { get; set; }
public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
public int HoursCount { get; set; }
public Dictionary<int, IStudentModel> Students { get; set; } = new();
}
}

View File

@ -7,5 +7,6 @@ namespace UniversityContracts.ViewModels
public int Id { get; set; }
public string Name { get; set; } = String.Empty;
public string RecordCardNumber { get; set; } = String.Empty;
public Dictionary<int, IExaminationResultModel> Results { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using UniversityDataModels.Models;
namespace UniversityContracts.ViewModels
{
public class UserViewModel : IUserModel
{
public int Id { get; set; }
public string Name { get; set; } = String.Empty;
public string Surname { get; set; } = String.Empty;
public string PhoneNumber { get; set; } = String.Empty;
public string Position { get; set; } = String.Empty;
public string Login { get; set; } = String.Empty;
public string Password { get; set; } = String.Empty;
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UniversityDataModels.Enums
namespace UniversityDataModels.Enums
{
public enum MarkType
{

View File

@ -4,5 +4,6 @@
{
DateTime Date { get; }
int HoursCount { get; }
Dictionary<int, IStudentModel> Students { get; }
}
}

View File

@ -4,5 +4,6 @@
{
String Name { get; }
String RecordCardNumber { get; }
Dictionary<int, IExaminationResultModel> Results { get; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UniversityDataModels.Models
{
public interface IUserModel : IId
{
string Name { get; }
string Surname { get; }
string PhoneNumber { get; }
string Position { get; }
string Login { get; }
string Password { get; }
}
}