public async Task <Response> Create(StudentCreateModel studentCreateModel) { using (var context = _applicationDbContextFactory.Create()) { var Lead = context.LeadInclude(studentCreateModel.LeadId); var StatusID = context.LeadStatuses.Where(i => i.Name == "Успешная сделка").Select(i => i.Id).FirstOrDefault(); Lead.LeadStatusId = StatusID; if (Lead == null) { return new ResponseObject <LeadDetailsModel> { Status = 500, Message = "Объект не найден" } } ; if (!context.Check <Lead>(studentCreateModel.LeadId)) { return new Response { Status = 500, Message = "Такого лида нет!" } } ; if (!context.Check <Group>(studentCreateModel.GroupId)) { return new Response { Status = 500, Message = "Такой группы нет!" } } ; var Student = Mapper.Map <Student>(Lead); var Entry = context.Students.Add(Student); context.Leads.Remove(Lead); context.SaveChanges(); _studentGroupService.Create(Entry.Entity.Id, studentCreateModel.GroupId); return(new Response { Status = 100, Message = "Запрос успешно прошел." }); } }
public async Task <Response> Create(int StudentId, int GroupId) { return(await _studentGroupService.Create(StudentId, GroupId)); }