public bool AddToBasket(Model.APIModel.Purchase.Basket item)
 {
     if (item.BasketID == 0)
     {
         return(_basketService.Post(item).Type == Model.Enum.Response.DataResponseType.SUCCESS);
     }
     else
     {
         return(_basketService.Put(item, item.BasketID.ToString()).Type == Model.Enum.Response.DataResponseType.SUCCESS);
     }
 }
        public IActionResult Register(RegisterPageModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = _customerService.Post(new Customer
                {
                    Forename = model.ForeName,
                    Surname  = model.SurName,
                });

                if (customer.Type == StoreFront.Model.Enum.Response.DataResponseType.SUCCESS)
                {
                    var customerID = Int32.Parse(customer.Details);


                    var addressStatus = _invoiceAddressService.Post(new StoreFront.Model.APIModel.Customer.InvoiceAddress
                    {
                        CustomerID = customerID,
                        Address1   = model.Address1,
                        Address2   = model.Address2 ?? "",
                        Address3   = model.Address3 ?? "",
                        Address4   = model.Town,
                        Address5   = "",
                        Postcode   = model.Postcode
                    });

                    var contactStatus = _contactService.Post(new Contact
                    {
                        CustomerID    = customerID,
                        Value         = model.Email,
                        ContactTypeID = 1
                    });


                    var securityStatus = _securityService.Post(new Security
                    {
                        CustomerID = customerID,
                        Username   = Encryption.EncryptString(model.Email),
                        Password   = Encryption.EncryptString(model.Password)
                    });


                    var page           = (StoreFront.Service.Register.Register)_page;
                    var transferStatus = _transferService.Post(new BasketTransfer
                    {
                        BasketGUID = page.GUID,
                        CustomerID = customerID
                    });



                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, customerID.ToString()),
                        new Claim(ClaimTypes.Role, "Administrator"),
                    };

                    var claimsIdentity = new ClaimsIdentity(
                        claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties
                    {
                        //AllowRefresh = <bool>,
                        // Refreshing the authentication session should be allowed.

                        ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                        // The time at which the authentication ticket expires. A
                        // value set here overrides the ExpireTimeSpan option of
                        // CookieAuthenticationOptions set with AddCookie.

                        IsPersistent = true,
                        // Whether the authentication session is persisted across
                        // multiple requests. Required when setting the
                        // ExpireTimeSpan option of CookieAuthenticationOptions
                        // set with AddCookie. Also required when setting
                        // ExpiresUtc.

                        //IssuedUtc = <DateTimeOffset>,
                        // The time at which the authentication ticket was issued.

                        //RedirectUri = <string>
                        // The full path or absolute URI to be used as an http
                        // redirect response value.
                    };

                    HttpContext.SignInAsync(
                        CookieAuthenticationDefaults.AuthenticationScheme,
                        new ClaimsPrincipal(claimsIdentity),
                        authProperties);

                    return(RedirectToAction("Index", "Delivery"));
                }
            }

            return(View("Index", _page.Load(model)));
        }
Exemple #3
0
        public DataResponse Process(DeliveryPageModel model)
        {
            var deliveryOptionExists = _basketDeliverySAL.Search(new List <SearchParameter> {
                new SearchParameter {
                    Name  = "CustomerID",
                    Value = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name)
                }
            });


            var deliveryOptionPrice = _deliveryOptionSAL.Get(model.DeliverySelection.ToString()).Price;

            if (!deliveryOptionExists.Any())
            {
                _basketDeliverySAL.Post(new BasketDelivery
                {
                    DeliveryOptionID = model.DeliverySelection,
                    CustomerID       = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                    Value            = deliveryOptionPrice
                });
            }
            else
            {
                _basketDeliverySAL.Put(new BasketDelivery
                {
                    DeliveryOptionID = model.DeliverySelection,
                    CustomerID       = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                    Value            = deliveryOptionPrice
                }, deliveryOptionExists.FirstOrDefault().CustomerID.ToString());
            }

            var addressExists = _deliveryAddressService.Get(_httpContextAccessor.HttpContext.User.Identity.Name);

            if (model.UserInvoiceAddress)
            {
                if (addressExists == null)
                {
                    _deliveryAddressService.Post(new Model.APIModel.Customer.DeliveryAddress
                    {
                        CustomerID = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                        Address1   = model.InvoiceAddress1,
                        Address2   = model.InvoiceAddress2,
                        Address3   = model.InvoiceAddress3,
                        Address4   = model.InvoiceAddress4,
                        Address5   = "",
                        Postcode   = model.Postcode
                    });
                }
                else
                {
                    _deliveryAddressService.Put(new Model.APIModel.Customer.DeliveryAddress
                    {
                        CustomerID = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                        Address1   = model.InvoiceAddress1,
                        Address2   = model.InvoiceAddress2,
                        Address3   = model.InvoiceAddress3,
                        Address4   = model.InvoiceAddress4,
                        Address5   = "",
                        Postcode   = model.Postcode
                    }, _httpContextAccessor.HttpContext.User.Identity.Name);
                }
            }

            if (model.NewAddress)
            {
                if (addressExists == null)
                {
                    _deliveryAddressService.Post(new Model.APIModel.Customer.DeliveryAddress
                    {
                        CustomerID = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                        Address1   = model.DeliveryAddress1,
                        Address2   = model.DeliveryAddress2,
                        Address3   = model.DeliveryAddress3,
                        Address4   = model.DeliveryAddress4,
                        Address5   = "",
                        Postcode   = model.DeliveryPostcode
                    });
                }
                else
                {
                    _deliveryAddressService.Put(new Model.APIModel.Customer.DeliveryAddress
                    {
                        CustomerID = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                        Address1   = model.DeliveryAddress1,
                        Address2   = model.DeliveryAddress2,
                        Address3   = model.DeliveryAddress3,
                        Address4   = model.DeliveryAddress4,
                        Address5   = "",
                        Postcode   = model.DeliveryPostcode
                    }, _httpContextAccessor.HttpContext.User.Identity.Name);
                }
            }

            return(new DataResponse {
                Type = Model.Enum.Response.DataResponseType.SUCCESS, Details = ""
            });
        }