Пример #1
0
        public IActionResult Summary()
        {
            ApplicationUser applicationUser;

            if (User.IsInRole(WebConstants.AdminRole))
            {
                if (HttpContext.Session.Get <int>(WebConstants.SessionInquiryId) != 0)
                {
                    //Cart was loaded using an inquiry
                    InquiryHeader inquiryHeader = _inqHRepo.FirstOrDefault(x => x.Id == HttpContext.Session.Get <int>(WebConstants.SessionInquiryId));
                    applicationUser = new ApplicationUser()
                    {
                        Email       = inquiryHeader.Email,
                        FullName    = inquiryHeader.FullName,
                        PhoneNumber = inquiryHeader.PhoneNumber
                    };
                }
                else
                {
                    applicationUser = new ApplicationUser();
                }

                var gateway     = _brain.GetGateway();
                var clientToken = gateway.ClientToken.Generate();
                ViewBag.ClientToken = clientToken;
            }
            else
            {
                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                //var userId = User.FindFirstValue(ClaimTypes.Name);

                applicationUser = _userRepo.FirstOrDefault(x => x.Id == claim.Value);
            }



            List <ShoppingCart> shoppingCartList = new List <ShoppingCart>();

            if (HttpContext.Session.Get <IEnumerable <ShoppingCart> >(WebConstants.SessionCart) != null &&
                HttpContext.Session.Get <IEnumerable <ShoppingCart> >(WebConstants.SessionCart).Count() > 0)
            {
                //Session exists
                shoppingCartList = HttpContext.Session.Get <IEnumerable <ShoppingCart> >(WebConstants.SessionCart).ToList();
            }
            List <int>            prodInCart = shoppingCartList.Select(i => i.ProductId).ToList();
            IEnumerable <Product> prodList   = _prodRepo.GetAll(x => prodInCart.Contains(x.Id));

            ProductUserVM = new ProductUserVM()
            {
                ApplicationUser = applicationUser,
            };
            foreach (var cartObj in shoppingCartList)
            {
                Product prodTemp = _prodRepo.FirstOrDefault(x => x.Id == cartObj.ProductId);
                prodTemp.TempSqFt = cartObj.SqFt;
                ProductUserVM.ProductList.Add(prodTemp);
            }
            return(View(ProductUserVM));
        }
Пример #2
0
        public IActionResult Delete()
        {
            InquiryHeader inquiryHeader = _inqHRepo.FirstOrDefault(u => u.Id == InquiryVM.InquiryHeader.Id);
            IEnumerable <InquiryDetail> inquiryDetails = _inqDRepo.GetAll(u => u.InquiryHeaderId == InquiryVM.InquiryHeader.Id);

            _inqDRepo.RemoveRange(inquiryDetails);
            _inqHRepo.Remove(inquiryHeader);
            _inqHRepo.Save();
            TempData[WC.Success] = "Action completed successfully";
            return(RedirectToAction(nameof(Index)));
        }
Пример #3
0
        public IActionResult Delete()
        {
            InquiryHeader inquiryHeader = _inquiryHeaderRepository.FirstOrDefault(x => x.Id == InquiryVM.InquiryHeader.Id);
            IEnumerable <InquiryDetail> inquiryDetails = _inquiryDetailRepository.GetAll(x => x.InquiryHeaderId == InquiryVM.InquiryHeader.Id);

            _inquiryDetailRepository.RemoveRange(inquiryDetails);
            _inquiryHeaderRepository.Remove(inquiryHeader);
            _inquiryHeaderRepository.Save();
            TempData[WC.Success] = "Inquiry deleted successfully";
            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        public IActionResult Delete()
        {
            InquiryHeader inquiryHeader = _inqHRepo.FirstOrDefault(u => u.Id == InquiryVM.InquiryHeader.Id);
            IEnumerable <InquiryDetail> inquiryDetails = _inqDRepo.GetAll(u => u.InquiryHeaderId == InquiryVM.InquiryHeader.Id);

            _inqDRepo.RemoveRange(inquiryDetails);
            _inqHRepo.Remove(inquiryHeader);
            _inqHRepo.Save();// or _inqDRepo.Save();

            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        public async Task <IActionResult> SummaryPost(ProductUserVM ProductUserVM)
        {
            var ClaimIdentity = (ClaimsIdentity)User.Identity;
            var Claim         = ClaimIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var PathToTemplate = _webHostEnvironment.WebRootPath + Path.DirectorySeparatorChar.ToString()
                                 + "templates" + Path.DirectorySeparatorChar.ToString() +
                                 "Inquiry.html";

            var    subject  = "New Inquiry";
            string HtmlBody = "";

            using (StreamReader sr = System.IO.File.OpenText(PathToTemplate))
            {
                HtmlBody = sr.ReadToEnd();
            }
            //Name: { 0}
            //Email: { 1}
            //Phone: { 2}
            //Products: {3}

            StringBuilder productListSB = new StringBuilder();

            foreach (var prod in ProductUserVM.ProductList)
            {
                productListSB.Append($" - Name: { prod.Name} <span style='font-size:14px;'> (ID: {prod.Id})</span><br />");
            }

            string messageBody = string.Format(HtmlBody,
                                               ProductUserVM.ApplicationUser.FullName,
                                               ProductUserVM.ApplicationUser.Email,
                                               ProductUserVM.ApplicationUser.PhoneNumber,
                                               productListSB.ToString());


            await _emailSender.SendEmailAsync(WC.EmailAdmin, subject, messageBody);

            InquiryHeader inquiryHeader = new InquiryHeader()
            {
                ApplicationUserId = Claim.Value,
                FullName          = ProductUserVM.ApplicationUser.FullName,
                Email             = ProductUserVM.ApplicationUser.Email,
                PhoneNumber       = ProductUserVM.ApplicationUser.PhoneNumber,
                InquiryDate       = DateTime.Now
            };

            _InHRepo.Add(inquiryHeader);
            _InHRepo.Save();

            foreach (var prod in ProductUserVM.ProductList)
            {
                InquiryDetail inquiryDetail = new InquiryDetail()
                {
                    InquiryHeaderId = inquiryHeader.Id,
                    ProductId       = prod.Id
                };
                _InDRepo.Add(inquiryDetail);
            }

            _InDRepo.Save();

            return(RedirectToAction(nameof(InquiryConfirmation)));
        }
Пример #6
0
        public async Task <IActionResult> SummaryPost(IFormCollection collection, ProductUserVM ProductUserVM)
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            if (User.IsInRole(WC.AdminRole))
            {
                //we need to create an order
                //var orderTotal = 0.0;
                //foreach(Product prod in ProductUserVM.ProductList)
                //{
                //    orderTotal += prod.Price * prod.TempSqFt;
                //}
                OrderHeader orderHeader = new OrderHeader()
                {
                    CreatedByUserId = claim.Value,
                    FinalOrderTotal = ProductUserVM.ProductList.Sum(x => x.TempSqFt * x.Price),
                    City            = ProductUserVM.ApplicationUser.City,
                    StreetAddress   = ProductUserVM.ApplicationUser.StreetAddress,
                    State           = ProductUserVM.ApplicationUser.State,
                    PostalCode      = ProductUserVM.ApplicationUser.PostalCode,
                    FullName        = ProductUserVM.ApplicationUser.FullName,
                    Email           = ProductUserVM.ApplicationUser.Email,
                    PhoneNumber     = ProductUserVM.ApplicationUser.PhoneNumber,
                    OrderDate       = DateTime.Now,
                    OrderStatus     = WC.StatusPending
                };
                _orderHRepo.Add(orderHeader);
                _orderHRepo.Save();

                foreach (var prod in ProductUserVM.ProductList)
                {
                    OrderDetail orderDetail = new OrderDetail()
                    {
                        OrderHeaderId = orderHeader.Id,
                        PricePerSqFt  = prod.Price,
                        Sqft          = prod.TempSqFt,
                        ProductId     = prod.Id
                    };
                    _orderDRepo.Add(orderDetail);
                }
                _orderDRepo.Save();

                string nonceFromTheClient = collection["payment_method_nonce"];

                var request = new TransactionRequest
                {
                    Amount             = Convert.ToDecimal(orderHeader.FinalOrderTotal),
                    PaymentMethodNonce = nonceFromTheClient,
                    OrderId            = orderHeader.Id.ToString(),
                    Options            = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = true
                    }
                };

                var gateway = _brain.GetGateway();
                Result <Transaction> result = gateway.Transaction.Sale(request);

                if (result.Target.ProcessorResponseText == "Approved")
                {
                    orderHeader.TransactionId = result.Target.Id;
                    orderHeader.OrderStatus   = WC.StatusApproved;
                }
                else
                {
                    orderHeader.OrderStatus = WC.StatusCancelled;
                }
                _orderHRepo.Save();
                return(RedirectToAction(nameof(InquiryConfirmation), new { id = orderHeader.Id }));
            }
            else
            {
                //we need to create an inquiry
                var PathToTemplate = _webHostEnvironment.WebRootPath + Path.DirectorySeparatorChar.ToString()
                                     + "templates" + Path.DirectorySeparatorChar.ToString() +
                                     "Inquiry.html";

                var    subject  = "New Inquiry";
                string HtmlBody = "";
                using (StreamReader sr = System.IO.File.OpenText(PathToTemplate))
                {
                    HtmlBody = sr.ReadToEnd();
                }
                //Name: { 0}
                //Email: { 1}
                //Phone: { 2}
                //Products: {3}

                StringBuilder productListSB = new StringBuilder();
                foreach (var prod in ProductUserVM.ProductList)
                {
                    productListSB.Append($" - Name: { prod.Name} <span style='font-size:14px;'> (ID: {prod.Id})</span><br />");
                }

                string messageBody = string.Format(HtmlBody,
                                                   ProductUserVM.ApplicationUser.FullName,
                                                   ProductUserVM.ApplicationUser.Email,
                                                   ProductUserVM.ApplicationUser.PhoneNumber,
                                                   productListSB.ToString());


                await _emailSender.SendEmailAsync(WC.EmailAdmin, subject, messageBody);

                InquiryHeader inquiryHeader = new InquiryHeader()
                {
                    ApplicationUserId = claim.Value,
                    FullName          = ProductUserVM.ApplicationUser.FullName,
                    Email             = ProductUserVM.ApplicationUser.Email,
                    PhoneNumber       = ProductUserVM.ApplicationUser.PhoneNumber,
                    InquiryDate       = DateTime.Now
                };

                _inqHRepo.Add(inquiryHeader);
                _inqHRepo.Save();

                foreach (var prod in ProductUserVM.ProductList)
                {
                    InquiryDetail inquiryDetail = new InquiryDetail()
                    {
                        InquiryHeaderId = inquiryHeader.Id,
                        ProductId       = prod.Id,
                    };
                    _inqDRepo.Add(inquiryDetail);
                }
                _inqDRepo.Save();
                TempData[WC.Success] = "Inquiry submitted successfully";
            }



            return(RedirectToAction(nameof(InquiryConfirmation)));
        }
Пример #7
0
        public IActionResult Summary()
        {
            ApplicationUser applicationUser;

            if (User.IsInRole(WC.AdminRole))
            {
                if (HttpContext.Session.Get <int>(WC.SessionInquiryId) != 0)
                {
                    //Cart has been loaded using an inquiry
                    InquiryHeader inquiryHeader = _inqHRepo.FirstOrDefault(u => u.Id == HttpContext.Session.Get <int>(WC.SessionInquiryId));
                    applicationUser = new ApplicationUser()
                    {
                        Email       = inquiryHeader.Email,
                        FullName    = inquiryHeader.FullName,
                        PhoneNumber = inquiryHeader.PhoneNumber
                    };
                }
                else
                {
                    applicationUser = new ApplicationUser();
                }

                //Payments logic:
                var gateway      = _brain.GetGateway();
                var clientTocken = gateway.ClientToken.Generate();
                ViewBag.ClientToken = clientTocken;
            }
            else
            {
                //Findout ID of Login User
                var clamsIdentity = (ClaimsIdentity)User.Identity;
                var claim         = clamsIdentity.FindFirst(ClaimTypes.NameIdentifier); // If user not Login (claim == null). ID will be in claim.Value
                //Anoter way to find UserID
                //var userId = User.FindFirstValue(ClaimTypes.Name);
                applicationUser = _userRepo.FirstOrDefault(u => u.Id == claim.Value);
            }


            //Get list of Products from Session "ShoppingCart"
            List <ShoppingCart> shoppingCartList = new List <ShoppingCart>();

            if (HttpContext.Session.Get <IEnumerable <ShoppingCart> >(WC.SessionCart) != null && HttpContext.Session.Get <IEnumerable <ShoppingCart> >(WC.SessionCart).Count() > 0)
            {
                //Session exists
                shoppingCartList = HttpContext.Session.Get <List <ShoppingCart> >(WC.SessionCart);
            }
            // Store all Id to new List
            List <int>            prodInCart = shoppingCartList.Select(i => i.ProductId).ToList();
            IEnumerable <Product> prodList   = _prodRepo.GetAll(u => prodInCart.Contains(u.Id));

            ProductUserVM = new ProductUserVM()
            {
                ApplicationUser = applicationUser //,
                                                  //ProductList = prodList.ToList()
            };

            foreach (var cartObj in shoppingCartList)
            {
                Product prodTemp = _prodRepo.FirstOrDefault(u => u.Id == cartObj.ProductId);
                prodTemp.TempSqFt = cartObj.SqFt;
                ProductUserVM.ProductList.Add(prodTemp);
            }


            return(View(ProductUserVM));
        }