private Client CreateModel(ClientBindingModel model, Client client, SchoolDataBase schoolDataBase) { if (model.Id.HasValue) { client.User.Login = model.Login; client.User.Password = model.Password; client.User.Name = model.ClientName; client.User.Patronymic = model.ClientPatronymic; client.User.Surname = model.ClientSurname; client.User.DateBirth = model.DateBirth; schoolDataBase.SaveChanges(); return(client); } User user = new User { Name = model.ClientName, Surname = model.ClientSurname, Patronymic = model.ClientPatronymic, DateBirth = model.DateBirth, Login = model.Login, Password = model.Password, }; schoolDataBase.Users.Add(user); schoolDataBase.SaveChanges(); client.UserId = user.Id; return(client); }
public List <SocietyViewModel> GetFilteredList(SocietyBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { return(context.Societies .Include(rec => rec.SocietyLessons) .ThenInclude(rec => rec.Lesson) .Include(rec => rec.Client) .ThenInclude(rec => rec.User) .Include(rec => rec.SocietyCosts) .ThenInclude(rec => rec.Cost) .Where(rec => model.DateFrom.HasValue && model.DateTo.HasValue && rec.ClientId == model.ClientId && rec.SocietyCosts.Any(rec => rec.Cost.CostDate.Date >= model.DateFrom.Value.Date && rec.Cost.CostDate.Date <= model.DateTo.Value.Date) || !model.DateFrom.HasValue && !model.DateTo.HasValue && rec.ClientId == model.ClientId && model.SelectedSocieties != null && model.SelectedSocieties.Contains(rec.Id) || !model.DateFrom.HasValue && !model.DateTo.HasValue && model.SelectedSocieties == null && rec.ClientId == model.ClientId) .Select(CreateViewModel) .ToList()); } }
public void Initialize() { var options = new DbContextOptionsBuilder <SchoolDataBase>() .UseInMemoryDatabase("Server=(localdb)\\mssqllocaldb;Database=StudentRepositoryTests;Trusted_Connection=True;ConnectRetryCount=0") .Options; _context = new SchoolDataBase(options); students = new List <Student>() { new Student() { Name = "Victor", Surname = "Dyshkant", Age = 19 }, new Student() { Name = "Alla", Surname = "Dyshkant", Age = 18 }, new Student() { Name = "Oleg", Surname = "Dyshkant", Age = 45 } }; _context.Students.AddRange(students); _context.SaveChanges(); studentRepository = new StudentRepository(_context); }
public void Update(PaymentBindingModel model) { using (var context = new SchoolDataBase()) { using (var transaction = context.Database.BeginTransaction()) { try { var payment = context.Payments.FirstOrDefault(rec => rec.Id == model.Id); if (payment == null) { throw new Exception("Кружок не найден"); } CreateModel(model, payment); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public void Initialization() { mapper = new MapperConfiguration(conf => { conf.AddProfile(new Mapping()); }).CreateMapper(); studentDTOs = new List <StudentDTO>() { new StudentDTO() { Id = 1, Name = "Victor", Surname = "Dyshkant", Age = 19 }, new StudentDTO() { Id = 2, Name = "Alla", Surname = "Dyshkant", Age = 17 }, new StudentDTO() { Id = 3, Name = "Oleg", Surname = "Dyshkant", Age = 45 } }; var options = new DbContextOptionsBuilder <SchoolDataBase>() .UseInMemoryDatabase("Server=(localdb)\\mssqllocaldb;Database=StudentServiceIntegrationTest;Trusted_Connection=True;ConnectRetryCount=0") .Options; SchoolDataBase context = new SchoolDataBase(options); context.Students.AddRange(mapper.Map <IEnumerable <Student> >(studentDTOs)); context.SaveChanges(); EFUnitOfWork unit = new EFUnitOfWork(context); studentService = new StudentService(unit, mapper); }
public void Initialize() { var options = new DbContextOptionsBuilder <SchoolDataBase>() .UseInMemoryDatabase("Server=(localdb)\\mssqllocaldb;Database=GroupRepositoryTests;Trusted_Connection=True;ConnectRetryCount=0") .Options; _context = new SchoolDataBase(options); groups = new List <Group>() { new Group() { Name = "SE-121", Capacity = 20 }, new Group() { Name = "SE-221", Capacity = 25 }, new Group() { Name = "SE-321", Capacity = 30 }, new Group() { Name = "SE-421", Capacity = 18 } }; _context.Groups.AddRange(groups); _context.SaveChanges(); }
public void Insert(ClientBindingModel model) { using (var schoolDataBase = new SchoolDataBase()) { schoolDataBase.Clients.Add(CreateModel(model, new Client(), schoolDataBase)); schoolDataBase.SaveChanges(); } }
public List <ClientViewModel> GetFullList() { using (var context = new SchoolDataBase()) { return(context.Clients .Include(rec => rec.User) .Select(CreateViewModel) .ToList()); } }
public void Initialization() { mapper = new MapperConfiguration(con => { con.AddProfiles(new Profile[] { new Mapping() }); }).CreateMapper(); groupDTOs = new List <GroupDTO>() { new GroupDTO() { Id = 1, Name = "SE-121", Capacity = 20 }, new GroupDTO() { Id = 2, Name = "SE-221", Capacity = 25 }, new GroupDTO() { Id = 3, Name = "SE-321", Capacity = 30 }, new GroupDTO() { Id = 4, Name = "SE-421", Capacity = 18 } }; studentDTOs = new List <StudentDTO>() { new StudentDTO() { Id = 1, Name = "Victor", Surname = "Dyshkant", Age = 19 }, new StudentDTO() { Id = 2, Name = "Alla", Surname = "Dyshkant", Age = 17 }, new StudentDTO() { Id = 3, Name = "Oleg", Surname = "Dyshkant", Age = 45 } }; var options = new DbContextOptionsBuilder <SchoolDataBase>() .UseInMemoryDatabase("Server=(localdb)\\mssqllocaldb;Database=GroupServiceIntegrationTest;Trusted_Connection=True;ConnectRetryCount=0") .Options; context = new SchoolDataBase(options); context.Groups.AddRange(mapper.Map <IEnumerable <Group> >(groupDTOs)); context.Students.AddRange(mapper.Map <IEnumerable <Student> >(studentDTOs)); context.SaveChanges(); EFUnitOfWork unit = new EFUnitOfWork(context); groupService = new GroupService(unit, mapper, NSubstitute.Substitute.For <IEventPublisher>()); }
public List <LessonViewModel> GetFullList() { using (var context = new SchoolDataBase()) { return(context.Lessons .Include(rec => rec.Employee) .ThenInclude(rec => rec.User) .Select(CreateViewModel) .ToList()); } }
public List <CostViewModel> GetFullList() { using (var context = new SchoolDataBase()) { return(context.Costs .Include(rec => rec.SocietyCosts) .ThenInclude(rec => rec.Society) .Select(CreateViewModel) .ToList()); } }
public List <CostViewModel> GetFilteredList(CostBindingModel model) { using (var context = new SchoolDataBase()) { return(context.SocietyCosts .Include(rec => rec.Cost) .Include(rec => rec.Society) .Where(rec => rec.Cost.CostDate.Date >= model.DateFrom.Date && rec.Cost.CostDate.Date <= model.DateTo.Date && rec.SocietyId == model.SocietyId) .Select(CreateViewModelOnSociety) .ToList()); } }
public void Update(ClientBindingModel model) { using (var schoolDataBase = new SchoolDataBase()) { var client = schoolDataBase.Clients.Include(rec => rec.User).FirstOrDefault(rec => rec.Id == model.Id); if (client == null) { throw new Exception("Клиент не найден"); } CreateModel(model, client, schoolDataBase); schoolDataBase.SaveChanges(); } }
public void Delete(SocietyBindingModel model) { using (var context = new SchoolDataBase()) { var society = context.Societies.FirstOrDefault(rec => rec.Id == model.Id); if (society == null) { throw new Exception("Кружок не найден"); } context.Societies.Remove(society); context.SaveChanges(); } }
public List <SocietyViewModel> GetFullList() { using (var context = new SchoolDataBase()) { return(context.Societies .Include(rec => rec.SocietyLessons) .ThenInclude(rec => rec.Lesson) .Include(rec => rec.Client) .ThenInclude(rec => rec.User) .Include(rec => rec.SocietyCosts) .ThenInclude(rec => rec.Cost) .Select(CreateViewModel) .ToList()); } }
public void Delete(PaymentBindingModel model) { using (var context = new SchoolDataBase()) { var payment = context.Payments.FirstOrDefault(rec => rec.Id == model.Id); if (payment == null) { throw new Exception("Кружок не найден"); } context.Payments.Remove(payment); context.SaveChanges(); } }
public List <LessonViewModel> GetFilteredList(LessonBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { return(context.Lessons .Include(rec => rec.Employee) .ThenInclude(rec => rec.User) .Where(rec => rec.LessonName.Contains(model.LessonName)) .Select(CreateViewModel) .ToList()); } }
public ClientViewModel GetElement(ClientBindingModel model) { if (model == null) { return(null); } using (var schoolDataBase = new SchoolDataBase()) { var client = schoolDataBase.Clients .Include(rec => rec.User) .FirstOrDefault(rec => rec.User.Login == model.Login || rec.UserId == model.Id); return(client != null?CreateViewModel(client) : null); } }
public List <PaymentViewModel> GetFilteredList(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { return(context.Payments .Include(rec => rec.Lesson) .Include(rec => rec.Client) .ThenInclude(rec => rec.User) .Where(rec => rec.ClientId == model.ClientId) .Select(CreateViewModel) .ToList()); } }
public PaymentViewModel GetElement(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { var payment = context.Payments .Include(rec => rec.Lesson) .Include(rec => rec.Client) .ThenInclude(rec => rec.User) .FirstOrDefault(rec => rec.Id == model.Id); return(payment != null?CreateViewModel(payment) : null); } }
public LessonViewModel GetElement(LessonBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { var lesson = context.Lessons .Include(rec => rec.Employee) .ThenInclude(rec => rec.User) .FirstOrDefault(rec => rec.LessonName == model.LessonName || rec.Id == model.Id); return(lesson != null?CreateViewModel(lesson) : null); } }
private Society CreateModel(SocietyBindingModel model, Society society, SchoolDataBase context) { society.SocietyName = model.SocietyName; society.AgeLimit = model.AgeLimit; society.Sum = model.Sum; society.ClientId = model.ClientId; if (society.Id == 0) { society.DateCreate = DateTime.Now; context.Societies.Add(society); context.SaveChanges(); } if (model.Id.HasValue) { var lessons = context.SocietyLessons .Where(rec => rec.SocietyId == model.Id.Value) .ToList(); context.SocietyLessons.RemoveRange(lessons .Where(rec => !model.Lessons.Contains(rec.LessonId)) .ToList()); context.SaveChanges(); foreach (var updateLesson in lessons) { model.Lessons.Remove(updateLesson.LessonId); } } foreach (var lesson in model.Lessons) { context.SocietyLessons.Add(new SocietyLesson { SocietyId = society.Id, LessonId = lesson }); context.SaveChanges(); } return(society); }
public void Insert(SocietyBindingModel model) { using (var context = new SchoolDataBase()) { using (var transaction = context.Database.BeginTransaction()) { try { CreateModel(model, new Society(), context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public SocietyViewModel GetElement(SocietyBindingModel model) { if (model == null) { return(null); } using (var context = new SchoolDataBase()) { var society = context.Societies .Include(rec => rec.SocietyLessons) .ThenInclude(rec => rec.Lesson) .Include(rec => rec.Client) .ThenInclude(rec => rec.User) .Include(rec => rec.SocietyCosts) .ThenInclude(rec => rec.Cost) .FirstOrDefault(rec => rec.SocietyName == model.SocietyName || rec.Id == model.Id); return(society != null?CreateViewModel(society) : null); } }
public void Insert(PaymentBindingModel model) { using (var context = new SchoolDataBase()) { using (var transaction = context.Database.BeginTransaction()) { try { model.PaymentDate = DateTime.Now; context.Payments.Add(CreateModel(model, new Payment())); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public StudentRepository(SchoolDataBase context) { _context = context; }
public GroupRepository(SchoolDataBase context) { _context = context; }
public EFUnitOfWork(SchoolDataBase context) { _context = context; }