Beispiel #1
0
 private async Task <IActionResult> EditCustomer(CustomerDto customer, bool canPurchase)
 {
     customer.CanPurchase = canPurchase;
     if (await _customerRepository.EditCustomer(_mapper.Map <CustomerRepoModel>(customer)))
     {
         if (!await _orderFacade.EditCustomer(_mapper.Map <OrderingCustomerDto>(customer)))
         {
             //write to local db top be sent later
         }
         return(Ok());
     }
     return(NotFound());
 }
        private async Task <IActionResult> NewOrEditedCustomer(CustomerDto customer)
        {
            if (customer != null)
            {
                getTokenDetails();
                if (clientId != null && clientId.Equals("customer_web_app"))
                {
                    int customerId = 0;
                    int.TryParse(tokenCustomerId, out customerId);
                    if (customerId < 1)
                    {
                        return(NotFound());
                    }
                    if ((customer.CustomerId != 0 && customerId != customer.CustomerId) ||
                        authId != customer.CustomerAuthId)
                    {
                        return(Forbid());
                    }
                    customer.CustomerId = customerId;
                }
                if (!await _customerRepository.CustomerExists(customer.CustomerId))
                {
                    if (await _customerRepository.NewCustomer(_mapper.Map <CustomerRepoModel>(customer)))
                    {
                        if (!await _orderFacade.NewCustomer(_mapper.Map <OrderingCustomerDto>(customer)))
                        {
                            //write to local db to be reattempted later
                        }
                        var reviewCustomer = new ReviewCustomerDto
                        {
                            CustomerId     = customer.CustomerId,
                            CustomerAuthId = customer.CustomerAuthId,
                            CustomerName   = customer.GivenName + " " + customer.FamilyName
                        };
                        if (!await _reviewFacade.NewCustomer(reviewCustomer))
                        {
                            //write to local db to be reattempted later
                        }
                        return(Ok());
                    }
                    return(NotFound());
                }
                else
                {
                    if (await _customerRepository.IsCustomerActive(customer.CustomerId))
                    {
/*                        if (User != null && User.Claims != null)
 *                      {
 *                          return Forbid();
 *                      }*/
                        if ((authId != null && customer.CustomerAuthId == authId) ||
                            (clientId != null && clientId.Equals("customer_ordering_api")))
                        {
                            var customerModel = _mapper.Map <CustomerDto>(await _customerRepository.GetCustomer(customer.CustomerId));
                            customer.CanPurchase = customerModel.CanPurchase;
                            if (await _customerRepository.EditCustomer(_mapper.Map <CustomerRepoModel>(customer)))
                            {
                                if (clientId != "customer_ordering_api")
                                {
                                    if (!await _orderFacade.EditCustomer(_mapper.Map <OrderingCustomerDto>(customer)))
                                    {
                                        //write to local db to be reattempted later
                                    }
                                }
                                var reviewCustomer = new ReviewCustomerDto
                                {
                                    CustomerId     = customer.CustomerId,
                                    CustomerAuthId = customer.CustomerAuthId,
                                    CustomerName   = customer.GivenName + " " + customer.FamilyName
                                };
                                if (!await _reviewFacade.EditCustomer(reviewCustomer))
                                {
                                    //write to local db to be reattempted later
                                }
                                return(Ok());
                            }
                        }
                        return(Forbid());
                    }
                }
                return(NotFound());
            }
            return(UnprocessableEntity());
        }