Esempio n. 1
0
        private async Task <ActionResultResponse> AddRelativesContacts(string customerId, List <CustomerRelativesContact> listCustomerRelativesContacts)
        {
            if (listCustomerRelativesContacts != null && listCustomerRelativesContacts.Count > 0)
            {
                var customerRelativesContacts = new List <CustomerRelativesContact>();
                foreach (var customerRelativesContact in listCustomerRelativesContacts)
                {
                    if (customerRelativesContacts.Any(x =>
                                                      x.FullName.Trim() == customerRelativesContact.FullName.Trim() &&
                                                      x.PhoneNumber.Trim() == customerRelativesContact.PhoneNumber.Trim()))
                    {
                        continue;
                    }

                    customerRelativesContacts.Add(new CustomerRelativesContact
                    {
                        CustomerId  = customerId,
                        FullName    = customerRelativesContact.FullName,
                        PhoneNumber = customerRelativesContact.PhoneNumber
                    });
                }

                if (customerRelativesContacts.Count > 0)
                {
                    var resultInsert = await _contactCustomerRepository.Inserts(customerRelativesContacts);

                    if (resultInsert <= 0)
                    {
                        await RollbackInsert(customerId);

                        return(new ActionResultResponse(resultInsert,
                                                        _sharedResourceService.GetString("Something went wrong. Please contact with administrator.")));
                    }
                }
                return(new ActionResultResponse(1, _customerResourceService.GetString("Add new relatives contacts successful.")));
            }
            return(new ActionResultResponse(0, _sharedResourceService.GetString(ErrorMessage.NothingChanges)));
        }