public async Task <IActionResult> UpdateAbonent(int userId, int id, AbonentDto AbonentDto) { var user = _userService.GetUser(userId); if (user != null) { var abonent = _abonentService.GetAbonent(user, id); if (abonent != null) { var answer = await _abonentService.UpdateAbonentAsync(user, id, AbonentDto.FirstName, AbonentDto.MiddleName, AbonentDto.LastName, AbonentDto.DateOfBirth, AbonentDto.Photo, AbonentDto.Sex, AbonentDto.Mail); if (answer.Succeeded) { return(Ok()); } return(BadRequest(answer.Errors)); } return(BadRequest("User -> Abonent not found")); } return(BadRequest("User not found")); }
public async Task <ActionResult <AbonentDto> > AddAbonent(int userId, AbonentDto AbonentDto) { var user = _userService.GetUser(userId); if (user != null) { var answer = await _abonentService.AddAbonentAsync(user, AbonentDto.FirstName, AbonentDto.MiddleName, AbonentDto.LastName, AbonentDto.DateOfBirth, AbonentDto.Photo, AbonentDto.Sex, AbonentDto.Mail); if (answer.Succeeded) { var answerDto = _abonentService.GetAbonent(user, AbonentDto.FirstName, AbonentDto.MiddleName, AbonentDto.LastName); if (answerDto.Succeeded) { AbonentDto = answerDto.Value; return(CreatedAtAction("GetAbonent", new { userId = AbonentDto.UserId, id = AbonentDto.Id }, AbonentDto)); } return(BadRequest(answerDto.Errors)); } return(BadRequest(answer.Errors)); } return(BadRequest("User not found")); }