Exemplo n.º 1
0
        private void GetBasket()
        {
            if (_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            {
                _basket = _basketService.Search(new List <SearchParameter>()
                {
                    new SearchParameter {
                        Name  = "CustomerID",
                        Value = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name)
                    }
                });

                _httpContextAccessor.HttpContext.Response.Cookies.Delete("GUID");
            }
            else
            {
                _basket = _basketService.Search(new List <SearchParameter>()
                {
                    new SearchParameter {
                        Name  = "BasketGUID",
                        Value = GUID
                    }
                });
            }
        }
Exemplo n.º 2
0
        public ProductDetailPageViewModel Load(params SearchParameter[] list)
        {
            ProductID = (int)list.FirstOrDefault(x => x.Name == "ProductID").Value;
            var product = _productService.Get(ProductID.ToString());
            var price   = _priceService.Search(new List <SearchParameter> {
                new SearchParameter {
                    Name  = "CountryID",
                    Value = Int32.Parse(_configuration["CountryID"])
                },
                new SearchParameter {
                    Name  = "ProductID",
                    Value = ProductID
                }
            });

            var productDetailPageModel = new ProductDetailPageModel
            {
                Content = (Model.Content.Content)_model
            };

            productDetailPageModel.AddProperty("product", product);
            productDetailPageModel.Price = price.FirstOrDefault().Value;

            return(new ProductDetailPageViewModel(productDetailPageModel));
        }
Exemplo n.º 3
0
        public DeliveryPageViewModel Load(params SearchParameter[] list)
        {
            var deliveryPageModel = new DeliveryPageModel
            {
                Content = (Model.Content.Content)_model
            };

            var options = _deliveryOptionSAL.Search(new List <SearchParameter> {
                new SearchParameter {
                    Name  = "CountryID",
                    Value = _configuration["CountryID"]
                }
            });

            var customerID = _httpContextAccessor.HttpContext.User.Identity.Name;

            var invoiceAddress = _invoiceAddressService.Get(customerID);

            deliveryPageModel.UserInvoiceAddress = true;
            deliveryPageModel.InvoiceAddress1    = invoiceAddress.Address1;
            deliveryPageModel.InvoiceAddress2    = invoiceAddress.Address2;
            deliveryPageModel.InvoiceAddress3    = invoiceAddress.Address3;
            deliveryPageModel.InvoiceAddress4    = invoiceAddress.Address4;
            deliveryPageModel.Postcode           = invoiceAddress.Postcode;
            deliveryPageModel.DeliveryOptions    = options;

            return(new DeliveryPageViewModel(deliveryPageModel));
        }
Exemplo n.º 4
0
        public DataResponse Process(PaymentPageModel model)
        {
            var result = _placeOrderSAL.Post(new PlaceOrder {
                CustomerID    = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name),
                CountryID     = Int32.Parse(_configuration["CountryID"]),
                TransactionID = "TempID" + DateTime.Now.TimeOfDay
            });

            var email = _contactSAL.Search(new List <SearchParameter>
            {
                new SearchParameter {
                    Name  = "CustomerID",
                    Value = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name)
                },
                new SearchParameter {
                    Name  = "ContactTypeID",
                    Value = (int)Model.Enum.Customer.ContactType.Email
                }
            });



            var emailBody = _viewRenderService.RenderToStringAsync("Render/Receipt", new object()).Result;

            SmtpClient client = new SmtpClient("relay.hostinguk.net");

            client.UseDefaultCredentials = true;

            MailMessage mailMessage = new MailMessage();

            mailMessage.From = new MailAddress("*****@*****.**");
            mailMessage.To.Add(email.FirstOrDefault().Value);

            mailMessage.BodyEncoding    = Encoding.UTF8;
            mailMessage.SubjectEncoding = Encoding.UTF8;

            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(emailBody);

            htmlView.ContentType = new ContentType("text/html");
            mailMessage.Body     = emailBody;
            mailMessage.AlternateViews.Add(htmlView);
            mailMessage.IsBodyHtml = true;
            mailMessage.Subject    = "Your receipt from totalsmarthomes.com";
            client.Send(mailMessage);

            return(new DataResponse {
                Type = Model.Enum.Response.DataResponseType.SUCCESS, Details = result.Details
            });
        }
Exemplo n.º 5
0
        public DataResponse Process(LoginPageModel model)
        {
            var security = _securitySAL.Search(new List <SearchParameter> {
                new  SearchParameter {
                    Name  = "Username",
                    Value = Encryption.EncryptString(model.Email)
                },
                new  SearchParameter {
                    Name  = "Password",
                    Value = Encryption.EncryptString(model.Password)
                }
            });

            if (security != null)
            {
                if (security.Any())
                {
                    var user = security.FirstOrDefault();

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

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

                    var authProperties = new Microsoft.AspNetCore.Authentication.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.
                    };

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

                    _basketTransferSAL.Post(new BasketTransfer {
                        CustomerID = user.CustomerID,
                        BasketGUID = GUID
                    });

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

            return(new DataResponse()
            {
                Type = Model.Enum.Response.DataResponseType.UNAUTHENTICATED, Details = ""
            });
        }
Exemplo n.º 6
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 = ""
            });
        }