Exemple #1
0
        public async Task <string> EditPhoneNumberAsync(string oldNumber, EditPersonPhoneViewModel model)
        {
            if (!string.IsNullOrEmpty(oldNumber))
            {
                var listPersonPhone = await _personPhoneRepository.FindAllAsync();

                var oldPersonPhone = listPersonPhone.SingleOrDefault(x => x.BusinessEntityID == model.PersonId && x.PhoneNumber == oldNumber && x.PhoneNumberTypeID == model.PhoneNumberTypeId);
                if (oldPersonPhone != null)
                {
                    var phoneNumeberType = _phoneNumberTypeService.Find(model.PhoneNumberTypeId);
                    if (phoneNumeberType != null)
                    {
                        if (!string.IsNullOrEmpty(model.Number))
                        {
                            var newPersonPhone = new PersonPhone
                            {
                                BusinessEntityID  = model.PersonId,
                                PhoneNumber       = model.Number,
                                PhoneNumberTypeID = model.PhoneNumberTypeId
                            };

                            var result = await _personPhoneRepository.EditAsync(oldPersonPhone, newPersonPhone);

                            if (result)
                            {
                                return("Successfully edit");
                            }
                            else
                            {
                                return("Error, try again!");
                            }
                        }
                        else
                        {
                            return("Number field cannot be empty!");
                        }
                    }
                    else
                    {
                        return("Number type does not exist!");
                    }
                }
                else
                {
                    return("Register not found!");
                }
            }
            else
            {
                return("Number field cannot be empty!");
            }
        }