Ejemplo n.º 1
0
        public async Task <string> InsertPhoneNumberAsync(InsertPersonPhoneViewModel model)
        {
            var person = await _personService.FindAsync(model.PersonId);

            if (person != null)
            {
                var phoneNumeberType = _phoneNumberTypeService.Find(model.PhoneNumberTypeId);
                if (phoneNumeberType != null)
                {
                    if (!string.IsNullOrEmpty(model.Number))
                    {
                        var personPhone = new PersonPhone
                        {
                            BusinessEntityID  = model.PersonId,
                            PhoneNumber       = model.Number,
                            PhoneNumberTypeID = model.PhoneNumberTypeId
                        };

                        var result = await _personPhoneRepository.InsertAsync(personPhone);

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