예제 #1
0
 public async Task <ActionResult> ChangeDeliveryAddressAsync([FromBody] ChangeDeliveryRequest request) => Ok(await accountService.ChangeDeliveryAddressAsync(request));
예제 #2
0
        public async Task <object> ChangeDeliveryAddressAsync(ChangeDeliveryRequest request)
        {
            var userMetas = await unitOfWork.UsersMetaRepository.All();

            var userDetails = await unitOfWork.UserRepository.Get(long.Parse(request.UserID));

            var user = userMetas.Where(u => u.UserId == long.Parse(request.UserID)).Count();


            //Update
            if (userMetas.Where(u => u.MetaKey == "billing_first_name" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single((u => u.MetaKey == "billing_first_name" & u.UserId == long.Parse(request.UserID)));

                billingFirstName.MetaValue = request.FirstName;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_first_name",
                    MetaValue = request.FirstName
                });
            }

            if (userMetas.Where(u => u.MetaKey == "billing_last_name" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_last_name"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.LastName;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_last_name",
                    MetaValue = request.LastName
                });
            }

            if (userMetas.Where(u => u.MetaKey == "billing_address_1" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_address_1"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.Address1;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_address_1",
                    MetaValue = request.Address1
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_address_2" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_address_2"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.Address2;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_address_2",
                    MetaValue = request.Address2
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_city" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_city"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.BillingCity;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_city",
                    MetaValue = request.BillingCity
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_postcode" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_postcode"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.BillingPostCode;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_postcode",
                    MetaValue = request.BillingPostCode
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_country" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_country"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.BillingCountry;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_country",
                    MetaValue = request.BillingCountry
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_state" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_state"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.BillingState;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_state",
                    MetaValue = request.BillingState
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_landmark" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_landmark"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.Landmark;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_landmark",
                    MetaValue = request.Landmark
                });
            }
            if (userMetas.Where(u => u.MetaKey == "billing_phone" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "billing_phone"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.BillingPhone;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "billing_phone",
                    MetaValue = request.BillingPhone
                });
            }


            //Shipping Details
            if (userMetas.Where(u => u.MetaKey == "shipping_address_1" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_address_1"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingAddress1;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_address_1",
                    MetaValue = request.ShippingAddress1
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_address_2" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_address_2"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingAddress2;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_address_2",
                    MetaValue = request.ShippingAddress2
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_city" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_city"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingCity;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_city",
                    MetaValue = request.ShippingCity
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_postcode" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_postcode"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingPostCode;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_postcode",
                    MetaValue = request.ShippingPostCode
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_country" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_country"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingCountry;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_country",
                    MetaValue = request.ShippingCountry
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_state" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_state"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingState;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_state",
                    MetaValue = request.ShippingState
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_landmark" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_landmark"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingLandmark;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_landmark",
                    MetaValue = request.ShippingLandmark
                });
            }
            if (userMetas.Where(u => u.MetaKey == "shipping_phone" & u.UserId == long.Parse(request.UserID)).Count() > 0)
            {
                var billingFirstName = await unitOfWork.UsersMetaRepository.Single(u => u.MetaKey == "shipping_phone"& u.UserId == long.Parse(request.UserID));

                billingFirstName.MetaValue = request.ShippingPhone;
                unitOfWork.UsersMetaRepository.Update(billingFirstName);
            }
            else
            {
                await unitOfWork.UsersMetaRepository.Add(new WpUsermeta()
                {
                    UserId    = long.Parse(request.UserID),
                    MetaKey   = "shipping_phone",
                    MetaValue = request.ShippingPhone
                });
            }

            await unitOfWork.SaveChangesAsync();


            var userMappings = await unitOfWork.ZohoCustomerMappingRepository.All();

            request.CustomerID = userMappings.Where(u => u.UserId == long.Parse(request.UserID)).SingleOrDefault().ZohoCustomerId;

            var updateCustomer = await this.httpClientFactory.PutAsync <CreateCustomerResponse, CreateCustomerRequest>(
                $"https://subscriptions.zoho.com/api/v1/customers/{request.CustomerID}", new CreateCustomerRequest()
            {
                FirstName      = request.FirstName,
                LastName       = request.LastName,
                BillingPhone   = request.BillingPhone,
                ShippingPhone  = request.ShippingPhone,
                BillingAddress = new BillingAddress()
                {
                    Attention = $"{request.FirstName} {request.LastName}",
                    Country   = "NG",
                    State     = request.BillingState,
                    City      = request.BillingCity,
                    Street    = $"{request.Address1},{request.Address2}"
                },
                ShippingAddress = new ShippingAddress()
                {
                    Attention = $"{request.FirstName} {request.LastName}",
                    Street    = $"{request.ShippingAddress1},{request.ShippingAddress2}",
                    Country   = "NG",
                    State     = request.ShippingState,
                    City      = request.ShippingCity
                }
            }, HttpClientFactory.APIType.ZohoSubscription, request.Token
                );


            return(new
            {
                Status = true,
                Message = "Successfully updated the details",
                UserDetails = GetUserDetails(Convert.ToString(request.UserID), userDetails)
            });
        }