Exemplo n.º 1
0
 public SuccesView()
 {
     InitializeComponent();
     context     = new SuccesViewModel();
     DataContext = context;
 }
Exemplo n.º 2
0
        public IActionResult Make(PurchaseViewModel purchase)
        {
            purchase.Surname   = purchase.Surname ?? " ";
            purchase.Name      = purchase.Name ?? " ";
            purchase.City      = purchase.City ?? " ";
            purchase.Street    = purchase.Street ?? " ";
            purchase.House     = purchase.House ?? " ";
            purchase.Apartment = purchase.Apartment ?? " ";

            var office   = Request.Form["offices"];
            var delivery = Request.Form["options"];

            string adress = purchase.Surname +
                            " " + purchase.Name +
                            " " + purchase.City +
                            " " + purchase.Street +
                            " " + purchase.House +
                            " " + purchase.Apartment +
                            " " + office +
                            " " + delivery;


            var costOffice = 0;

            if (office == "Meest")
            {
                costOffice = 20;
            }
            else if (office == "New Post")
            {
                costOffice = 35;
            }
            else
            {
                costOffice = 15;
            }

            var deliveryCost = delivery == "On home" ? 10 : 0;
            var user         = unit.UserRepository.Get(x => x.Email == User.Identity.Name).FirstOrDefault();

            var     carts = unit.ShoppingCartRepository.Get(x => x.UserId == user.Id, includeProperties: "Product");
            decimal total = carts.Sum(x => x.Product.Price * x.Count);

            total += (costOffice + deliveryCost);
            Purchase np = new Purchase()
            {
                UserId       = user.Id,
                Adress       = adress,
                FullPrice    = total,
                CreationTime = DateTime.Now
            };
            var time = np.CreationTime;

            unit.PurchaseRepository.Insert(np);
            unit.Save();
            foreach (var i in carts)
            {
                var npr = new PurchaseProduct()
                {
                    PurchaseId = np.Id,
                    ProductId  = i.ProductId,
                    Count      = i.Count
                };
                unit.PurchaseProductRepository.Insert(npr);
                unit
                .ShoppingCartRepository
                .Delete(i);
                unit.Save();
            }
            unit.Save();
            var succes = new SuccesViewModel()
            {
                TotalPrice = total
            };

            return(View("Success", succes));
        }