Exemple #1
0
        public async Task <PersonPhoneResponse> FindAsync(string key)
        {
            try
            {
                var result = await _personPhoneService.FindAsync(key);

                var response = new PersonPhoneResponse
                {
                    PersonPhoneObjects = new List <PersonPhoneDto>()
                };
                response.PersonPhoneObjects.Add(_mapper.Map <PersonPhoneDto>(result));
                return(response);
            }
            catch (System.Exception ex)
            {
                return(new PersonPhoneResponse
                {
                    Success = false,
                    Errors = new List <object>
                    {
                        ex.Message
                    }
                });
            }
        }
Exemple #2
0
        public async Task <PersonPhoneResponse> UpdatePersonPhone(int id, PersonPhoneDto personPhone)
        {
            var person = await _personService.Find(personPhone.PersonId);

            var personPhoneUpdate = await _personPhoneService.Find(id);

            personPhoneUpdate.PhoneNumber     = personPhone.PhoneNumber;
            personPhoneUpdate.PhoneNumberType =
                await _phoneNumberTypeService.Find(x => x.Name == personPhone.PhoneNumberType);

            personPhoneUpdate.Person = person;


            await _personPhoneService.Update(personPhoneUpdate);


            var response = new PersonPhoneResponse
            {
                PersonPhoneObject = new PersonPhoneDto
                {
                    BusinessEntityID = personPhoneUpdate.BusinessEntityID,
                    PersonId         = personPhoneUpdate.Person.BusinessEntityID,
                    PhoneNumber      = personPhoneUpdate.PhoneNumber,
                    PhoneNumberType  = personPhoneUpdate.PhoneNumberType.Name
                }
            };

            return(response);
        }
Exemple #3
0
        public async Task <PersonPhoneResponse> AddPersonPhone(PersonPhoneDto personPhone)
        {
            var person = await _personService.Find(personPhone.PersonId);

            var newPersonPhone = new PersonPhone
            {
                PhoneNumber     = personPhone.PhoneNumber,
                PhoneNumberType = await _phoneNumberTypeService.Find(x => x.Name == personPhone.PhoneNumberType),
                Person          = person
            };

            await _personPhoneService.Add(newPersonPhone);


            var response = new PersonPhoneResponse
            {
                PersonPhoneObject = new PersonPhoneDto
                {
                    BusinessEntityID = newPersonPhone.BusinessEntityID,
                    PersonId         = newPersonPhone.Person.BusinessEntityID,
                    PhoneNumber      = newPersonPhone.PhoneNumber,
                    PhoneNumberType  = newPersonPhone.PhoneNumberType.Name
                }
            };

            return(response);
        }
Exemple #4
0
        public async Task <PersonPhoneResponse> PutAsync(PersonPhoneRequest person)
        {
            var result = await _personPhoneService.PutAsync(_mapper.Map <PersonPhone>(person));

            var response = new PersonPhoneResponse();

            response.PersonPhoneObject = _mapper.Map <PersonPhoneDto>(result);
            return(response);
        }
Exemple #5
0
        public async Task <PersonPhoneResponse> Delete(int id)
        {
            var personPhoneResponse = await _personPhoneService.Delete(id);

            var response = new PersonPhoneResponse();

            response.PersonPhoneObject = new PersonPhoneDto();
            response.PersonPhoneObject = _mapper.Map <PersonPhone, PersonPhoneDto>(personPhoneResponse);
            return(response);
        }
Exemple #6
0
        public async Task <PersonPhoneResponse> FindAllByIdAsync(int businessEntityID)
        {
            var result = await _personPhoneService.FindAllByIdAsync(businessEntityID);

            var response = new PersonPhoneResponse();

            response.PersonPhoneObjects = new List <PersonPhoneDto>();
            response.PersonPhoneObjects.AddRange(result.Select(x => _mapper.Map <PersonPhoneDto>(x)));
            return(response);
        }
Exemple #7
0
        public async Task <PersonPhoneResponse> Update(PersonPhoneDto personPhoneDto)
        {
            var personPhone         = _mapper.Map <PersonPhoneDto, PersonPhone>(personPhoneDto);
            var personPhoneResponse = await _personPhoneService.Update(personPhone);

            var response = new PersonPhoneResponse();

            response.PersonPhoneObject = new PersonPhoneDto();
            response.PersonPhoneObject = _mapper.Map <PersonPhone, PersonPhoneDto>(personPhoneResponse);
            return(response);
        }
Exemple #8
0
        public async Task <PersonPhoneResponse> FindAllAsync()
        {
            var result = await personPhoneService.FindAllAsync();

            var response = new PersonPhoneResponse();

            response.PersonPhoneObjects = new List <Dtos.PersonPhoneDto>();
            response.PersonPhoneObjects.AddRange(result.Select(x => mapper.Map <PersonPhoneDto>(x)));

            return(response);
        }
Exemple #9
0
        public async Task <PersonPhoneResponse> FindByIdAsync(int id)
        {
            var result = await personPhoneService.FindById(id);

            var response = new PersonPhoneResponse();

            response.PersonPhoneObjects = new List <PersonPhoneDto>();
            response.PersonPhoneObjects.Add(mapper.Map <PersonPhoneDto>(result));

            return(response);
        }
Exemple #10
0
        public async Task <PersonPhoneResponse> RemovePersonPhone(PersonPhoneRequest request)
        {
            request.PersonPhone.PhoneNumberType = null;

            var result = await personPhoneService.RemovePersonPhone(mapper.Map <PersonPhone>(request.PersonPhone));

            var response = new PersonPhoneResponse();

            response.Success = result;

            return(response);
        }
Exemple #11
0
        public async Task <PersonPhoneResponse> EditPersonPhone(PersonPhoneRequest request)
        {
            var result = await personPhoneService.EditPersonPhone(mapper.Map <PersonPhone>(request.PersonPhone),
                                                                  mapper.Map <PersonPhone>(request.Extra));

            var response = new PersonPhoneResponse();

            response.PersonPhoneObjects.Add(result ? request.PersonPhone : null);
            response.Success = result;

            return(response);
        }
Exemple #12
0
        public async Task <PersonPhoneResponse> FindPersonPhone(int id)
        {
            var result = await _personPhoneService.Find(id);

            var response = new PersonPhoneResponse
            {
                PersonPhoneObject = new PersonPhoneDto
                {
                    BusinessEntityID = result.BusinessEntityID,
                    PersonId         = result.Person.BusinessEntityID,
                    PhoneNumber      = result.PhoneNumber,
                    PhoneNumberType  = result.PhoneNumberType.Name
                }
            };

            return(response);
        }
Exemple #13
0
        public PersonPhoneResponse SelectAllPersonPhone()
        {
            var response = new PersonPhoneResponse();

            try
            {
                var result = _personPhoneService.SelectAllPersonPhone();
                response.Success       = true;
                response.PersonObjects = result;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex);
            }

            return(response);
        }
Exemple #14
0
        public async Task <PersonPhoneResponse> RemovePersonPhone(int id)
        {
            var removedPersonPhone = await _personPhoneService.Find(x => x.BusinessEntityID == id);

            var response = new PersonPhoneResponse
            {
                PersonPhoneObject = new PersonPhoneDto
                {
                    BusinessEntityID = removedPersonPhone.BusinessEntityID,
                    PersonId         = removedPersonPhone.Person.BusinessEntityID,
                    PhoneNumber      = removedPersonPhone.PhoneNumber,
                    PhoneNumberType  = removedPersonPhone.PhoneNumberType.Name
                }
            };

            await _personPhoneService.Remove(removedPersonPhone);

            return(response);
        }
Exemple #15
0
        public PersonPhoneResponse SelectPersonPhone(string phoneNumber)
        {
            var request = new PersonPhoneResponseDto()
            {
                PhoneNumber = phoneNumber,
            };

            var response = new PersonPhoneResponse();

            try
            {
                var result = _personPhoneService.SelectPersonPhone(request);
                response.Success       = true;
                response.PersonObjects = result;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex);
            }

            return(response);
        }
Exemple #16
0
        public PersonPhoneResponse DeletePersonPhone(int personId, int typePhoneId, string phoneNumber)
        {
            var request = new PersonPhone()
            {
                BusinessEntityID  = personId,
                PhoneNumber       = phoneNumber,
                PhoneNumberTypeID = typePhoneId
            };

            var response = new PersonPhoneResponse();

            try
            {
                var result = _personPhoneService.DeletePersonPhone(request);
                response.Success = result;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex);
            }

            return(response);
        }
Exemple #17
0
        public PersonPhoneResponse UpdatePersonPhone(PersonPhoneResponseDto objReq, string newPhoneNumber)
        {
            var request = new PersonPhone()
            {
                BusinessEntityID  = objReq.BusinessEntityID,
                PhoneNumber       = objReq.PhoneNumber,
                PhoneNumberTypeID = objReq.PhoneNumberTypeID,
            };

            var response = new PersonPhoneResponse();

            try
            {
                var result = _personPhoneService.UpdatePersonPhone(request, newPhoneNumber);
                response.Success = result;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex);
            }

            return(response);
        }