Exemple #1
0
        //[CheckPermission(PageId.Position, Permission.Update)]
        public async Task <IActionResult> Update(string customerId, string id, [FromBody] ContactCustomerMeta contactCustomerMeta)
        {
            var result = await _contactCustomerService.Update(CurrentUser.TenantId, id, contactCustomerMeta);

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

            return(Ok(result));
        }
        public async Task <ActionResultResponse <string> > Insert(string tenantId, ContactCustomerMeta contactCustomerMeta)
        {
            var contactCustomer = new CustomerRelativesContact
            {
                FullName    = contactCustomerMeta.FullName,
                CustomerId  = contactCustomerMeta.CustomerId,
                PhoneNumber = contactCustomerMeta.PhoneNumber
            };

            var resultInsert = await _contactCustomerRepository.Insert(contactCustomer);

            if (resultInsert > 0)
            {
                return(new ActionResultResponse <string>(resultInsert,
                                                         _customerResourceService.GetString("Add new contact successful."), string.Empty, contactCustomer.Id));
            }

            await RollbackInsert(contactCustomer.Id);

            return(new ActionResultResponse <string>(-4, _customerResourceService.GetString("Can not insert new ContactCustomer. Please contact with administrator.")));
        }
        public async Task <ActionResultResponse> Update(string tenantId, string id, ContactCustomerMeta contactCustomerMeta)
        {
            var contactCustomerInfo = await _contactCustomerRepository.GetInfo(id);

            if (contactCustomerInfo == null)
            {
                return(new ActionResultResponse(-1, _customerResourceService.GetString("ContactCustomer does not exists.")));
            }

            if (contactCustomerInfo.ConcurrencyStamp != contactCustomerMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-2, _customerResourceService.GetString("The ContactCustomer already updated by other people. You can not update this ContactCustomer.")));
            }

            contactCustomerInfo.ConcurrencyStamp = Guid.NewGuid().ToString();
            contactCustomerInfo.FullName         = contactCustomerMeta.FullName;
            contactCustomerInfo.CustomerId       = contactCustomerMeta.CustomerId;
            contactCustomerInfo.PhoneNumber      = contactCustomerMeta.PhoneNumber;
            await _contactCustomerRepository.Update(contactCustomerInfo);

            return(new ActionResultResponse(1, _customerResourceService.GetString("Update ContactCustomer successful.")));
        }