public async Task <IActionResult> UpdateGroupPhone(int userId, int id, GroupPhoneDto groupPhoneDto) { var user = _userService.GetUser(userId); if (user != null) { var groupPhone = user.GroupPhones.FirstOrDefault(gp => gp.Id == id); if (groupPhone != null) { var answer = await _groupPhoneService.UpdateGroupPhoneAsync(user, id, groupPhoneDto.Name); if (answer.Succeeded) { return(Ok()); } return(BadRequest(answer.Errors)); } return(BadRequest("User -> GroupPhone not found")); } return(BadRequest("User not found")); }
public async Task <ActionResult <GroupPhoneDto> > AddGroupPhone(int userId, GroupPhoneDto groupPhoneDto) { groupPhoneDto.UserId = userId; var user = _userService.GetUser(userId); if (user != null) { var answer = await _groupPhoneService.AddGroupPhoneAsync(user, (string)groupPhoneDto.Name); if (answer.Succeeded) { var answerDto = _groupPhoneService.GetGroupPhone(user, (string)groupPhoneDto.Name); if (answerDto.Succeeded) { groupPhoneDto = answerDto.Value; return(CreatedAtAction("GetGroupPhone", new { userId = groupPhoneDto.UserId, id = groupPhoneDto.Id }, groupPhoneDto)); } return(BadRequest(answerDto.Errors)); } return(BadRequest(answer.Errors)); } return(BadRequest("User not found")); }
public async Task <ActionResult <GroupPhoneDto> > DeleteGroupPhone(int userId, int id) { var user = _userService.GetUser(userId); if (user != null) { var groupPhone = user.GroupPhones.FirstOrDefault(u => u.Id == id); if (groupPhone != null) { GroupPhoneDto dto = new GroupPhoneDto() { Id = groupPhone.Id, UserId = groupPhone.UserId, Name = groupPhone.Name }; await _groupPhoneService.DeleteGroupPhoneAsync(user, groupPhone); return(dto); } return(BadRequest("User -> GroupPhone not found")); } return(BadRequest("User not found")); }