public async Task <PhoneDto> AddPhone(AddPhoneDto addPhoneDto) { var user = await _repository.GetById(addPhoneDto.objectId); if (user == null) { return(null); } await _repository.LoadCollection(user, c => c.UserPhones); if (user.UserPhones.All(c => c.Phone == addPhoneDto.Phone)) { return(null); } var phone = new UserPhone() { UserId = user.Id, Phone = addPhoneDto.Phone }; user.UserPhones.Add(phone); await _repository.Update(user); if (user.CanWorkAsAgent) { RemoveCash(); } return(_mapper.Map <PhoneDto>(phone)); }
public async Task <ErrorRepsonse <PhoneDto> > AddPhone(AddPhoneDto addPhoneDto) { var client = await _repository.GetById(addPhoneDto.objectId); var response = new ErrorRepsonse <PhoneDto>(); if (client == null) { response.Errors.Add("Not.Found"); return(response); } await _repository.LoadCollection(client, c => c.ClientPhones); if (client.ClientPhones.Any(c => c.Phone == addPhoneDto.Phone)) { response.Errors.Add("Dublicate"); return(response); } var clientPhone = new ClientPhone() { ClientId = client.Id, Phone = addPhoneDto.Phone }; client.ClientPhones.Add(clientPhone); await _repository.Update(client); response.Data = _mapper.Map <PhoneDto>(clientPhone); RemoveCash(); return(response); }
public Person AddPhone(AddPhoneDto addPhoneDto) { List <Phone> phones = new List <Phone>(); foreach (var phone in addPhoneDto.Phones) { phones.Add(new Phone { PersonId = addPhoneDto.PersonId, PhoneNumber = phone }); } return(_personRepository.AddPhone(phones)); }
public async Task <IActionResult> AddPhone([FromBody] AddPhoneDto addPhoneDto) { try { var data = await _userCashedService.AddPhone(addPhoneDto); _countryCashedService.RemoveCash(); return(Ok(data)); } catch (Exception ex) { _logging.WriteExption(ex); return(BadRequest()); } }
public async Task <IActionResult> AddPhone([FromBody] AddPhoneDto addPhoneDto) { try { var result = await _clientCashedService.AddPhone(addPhoneDto); if (result.Errors.Any()) { return(Conflict()); } return(Ok(result.Data)); } catch (Exception ex) { _logging.WriteExption(ex); return(BadRequest()); } }
public IActionResult AddPhone(AddPhoneDto addPhoneDto) { var person = _personApplicationService.AddPhone(addPhoneDto); return(Ok(person)); }