public async Task <ActionResultResponse> Update(string tenantId, string id, CustomerContactMeta customerContactMeta)
        {
            var customerContactInfo = await _customerContactRepository.GetInfo(id);

            if (customerContactInfo == null)
            {
                return(new ActionResultResponse(-2, _CustomerResourceService.GetString("CustomerContact does not exists.")));
            }

            if (customerContactInfo.ConcurrencyStamp != customerContactMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-3, _CustomerResourceService.GetString("The CustomerContact already updated by other people. You can not update this CustomerContact.")));
            }

            customerContactInfo.ConcurrencyStamp = Guid.NewGuid().ToString();
            customerContactInfo.ContactType      = customerContactMeta.ContactType;
            customerContactInfo.ContactValue     = customerContactMeta.ContactValue;
            var result = await _customerContactRepository.Update(customerContactInfo);

            if (result <= 0)
            {
                return(new ActionResultResponse(-4, _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            await UpdateCustomerUnsignName(customerContactInfo.CustomerId);

            return(new ActionResultResponse(1, _CustomerResourceService.GetString("Update CustomerContact successful.")));
        }
        public async Task <ActionResultResponse <string> > Insert(string tenantId, CustomerContactMeta customerContactMeta)
        {
            CustomerContact customerContact = new CustomerContact
            {
                CustomerId   = customerContactMeta.CustomerId,
                ContactType  = customerContactMeta.ContactType,
                ContactValue = customerContactMeta.ContactValue
            };

            var resultInsert = await _customerContactRepository.Insert(customerContact);

            if (resultInsert > 0)
            {
                //var Customer = await _CustomerRepository.GetInfo(CustomerContactMeta.CustomerId);
                //if (CustomerContactMeta.ContactType == ContactType.Email)
                //{
                //    Customer.Email = CustomerContactMeta.ContactValue;
                //}
                //else
                //{
                //    Customer.PhoneNumber = CustomerContactMeta.ContactValue;
                //}
                //Customer.UnsignName = await Unsign(CustomerContactMeta);
                //await _CustomerRepository.Update(Customer);
                await UpdateCustomerUnsignName(customerContactMeta.CustomerId);

                return(new ActionResultResponse <string>(resultInsert, _CustomerResourceService.GetString("Add new CustomerContact successful."), string.Empty, customerContact.Id));
            }

            await RollbackInsert(customerContact.Id);

            return(new ActionResultResponse <string>(-4, _CustomerResourceService.GetString("Can not insert new CustomerContact. Please contact with administrator.")));
        }
Пример #3
0
        //[CheckPermission(PageId.Position, Permission.Update)]
        public async Task <IActionResult> Update(string customerId, string id, [FromBody] CustomerContactMeta customerContactMeta)
        {
            var result = await _customerContactService.Update(CurrentUser.TenantId, id, customerContactMeta);

            //var result = await _CustomerContactService.Update("1", id, CustomerContactMeta);
            if (result.Code < 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }