public async Task <Diver> AddDiverAsync(EditDiverModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var poco = _mapper.Map <DiverPoco>(model); var added = await _diverRepository.AddAsync(poco); var diver = _mapper.Map <Diver>(added); return(diver); }
public async Task <Diver> EditDiverAsync(int diverId, EditDiverModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var existing = await _diverRepository.GetAsync(diverId); if (existing == null) { throw new NotFoundException("Водолаз не найден."); } existing.LastName = model.LastName; existing.FirstName = model.FirstName; existing.MiddleName = model.MiddleName; existing.PhotoUrl = model.PhotoUrl; existing.BirthDate = model.BirthDate; existing.RescueStationId = model.RescueStationId; existing.MedicalExaminationDate = model.MedicalExaminationDate; existing.Address = model.Address; existing.Qualification = model.Qualification; existing.PersonalBookNumber = model.PersonalBookNumber; existing.PersonalBookIssueDate = model.PersonalBookIssueDate; existing.PersonalBookProtocolNumber = model.PersonalBookProtocolNumber; var updated = await _diverRepository.UpdateAsync(existing); var hours = await SetWorkingHours(updated.DiverId, model.WorkingTime); var diver = _mapper.Map <Diver>(updated); diver.WorkingTime = hours; return(diver); }
public async Task <IActionResult> Add(EditDiverModel model) { _ = await _diverService.AddDiverAsync(model); return(RedirectToAction("Index", "Divers")); }
public async Task <IActionResult> UpdateAsync([FromRoute] int diverId, [FromBody, Required] EditDiverModel model) { var updated = await _diverService.EditDiverAsync(diverId, model); return(Ok(updated)); }
public async Task <IActionResult> CreateAsync([FromBody, Required] EditDiverModel model) { var added = await _diverService.AddDiverAsync(model); return(Created("api/divers", added)); }