public async Task <Response> FullCreate(StudentFullCreateModel studentFullCreateModel) { using (var context = _applicationDbContextFactory.Create()) { var Student = Mapper.Map <Student>(studentFullCreateModel); if (!context.Check <City>(studentFullCreateModel.CityId)) { return new Response { Status = 500, Message = "Такого города нет!" } } ; if (context.Students.Any(i => i.Id == Student.Id)) { return new Response { Status = 500, Message = "Такой студент уже существует!" } } ; if (!context.Check <Group>(studentFullCreateModel.GroupId)) { return new Response { Status = 500, Message = "Такой группы нет!" } } ; Student.Surname = studentFullCreateModel.Surname; Student.Name = studentFullCreateModel.Name; Student.MiddleName = studentFullCreateModel.MiddleName; Student.CityId = studentFullCreateModel.CityId; Student.Phone = studentFullCreateModel.Phone; Student.Email = studentFullCreateModel.Email; Student.Address = studentFullCreateModel.Address; Student.HasLaptop = studentFullCreateModel.HasLaptop; var Entry = context.Students.Add(Student); context.SaveChanges(); _studentGroupService.Create(Entry.Entity.Id, studentFullCreateModel.GroupId); return(new Response { Status = 100, Message = "Запрос успешно прошел." }); } }
public async Task <ActionResult <Response> > Create(StudentFullCreateModel model) { return(await _studentService.FullCreate(model)); }