public Order AddOrder(Order order)
 {
     return(orderManagement.AddOrder(order));
 }
        public ActionResult Checkout(FormCollection form)
        {
            var useremail = TryGetUserId();
            var cart      = Management.Get(useremail);
            var user      = UserManagement.Get(useremail);

            Order       order   = new Order();
            OrderNumber Onumber = new OrderNumber();

            CheckAuditPattern(order, true);
            CheckAuditPattern(Onumber, true);

            var ListOnumbers = OrderManagement.GetAllOrderNumber();

            var od = ListOnumbers.OrderByDescending(p => p.Id)
                     .FirstOrDefault();

            if (od == null)
            {
                Onumber.Number = 0001;
            }
            else
            {
                Onumber.Number = 000 + (od.Id + 1);
            }

            order.OrderDate  = DateTime.Now;
            order.ItemCount  = cart.CartItems.Count();
            order.TotalPrice = Convert.ToDouble(cart.CartItems.Sum(item => item.Price));
            order.UserId     = user.Id;

            //CheckAuditPattern(order.OrderItems, true);

            order.OrderItems = cart.CartItems.Select(x => new OrderDetail()
            {
                ProductId = x.ProductId,
                Price     = x.Price,
                Quantity  = x.Quantity,
                CreatedOn = DateTime.Now,
                ChangedOn = DateTime.Now
            }).ToList();


            try
            {
                Management.Remove(cart.Id);                 //LIMPIA EL CARRITO
                OrderManagement.AddOrderNumber(Onumber);
                order.OrderNumber = Onumber.Id;
                OrderManagement.AddOrder(order);                 //AGREGA LA ORDEN

                foreach (var item in order.OrderItems)
                {
                    var prod = ProductManagement.Get(item.ProductId);
                    prod.QuantitySold += item.Quantity;
                    ProductManagement.Update(prod);
                }
            }
            catch (Exception e)
            {
                ExceptionContext ex = new ExceptionContext();
                ex.Exception = e.InnerException;
                OnException(ex);
            }

            return(View(order));
        }
        public ActionResult PayAndFinish(string cartname, string cartnumber, string cartexp, int cartsec = 0, int addresid = 0)
        {
            if (Session["Login"] != null)
            {
                AppUsers gelen   = (AppUsers)Session["Login"];
                int      gelenid = gelen.UserID;
                string   hata;
                string   cartsecstring = cartsec.ToString();


                if (addresid > 0 && !string.IsNullOrEmpty(cartname) && !string.IsNullOrEmpty(cartexp))
                {
                    if (cartsecstring.Length >= 4 && cartsecstring.Length <= 6)
                    {
                        if (cartnumber.Length >= 16 && cartnumber.Length <= 16)
                        {
                            if (cartexp.Length >= 3 && cartexp.Length <= 7)
                            {
                                OrderManagement.AddOrder(cartname, cartnumber, cartexp, cartsec, addresid, gelenid);
                                var orderid = OrderManagement.LastOrderID(gelenid);

                                Session.Add("OrderID", orderid);
                                return(RedirectToAction("PayConfirmation", "PayInfo", new { @id = 1 }));
                            }
                            else
                            {
                                hata = "Son Kullanma süreniz hatalı";
                                Session.Add("payeror", hata);
                                Session.Add("addresid", addresid);
                                return(RedirectToAction("Index", "PayInfo"));
                            }
                        }
                        else
                        {
                            hata = "Kart numaranız eksik veya hatalı";
                            Session.Add("payeror", hata);
                            Session.Add("addresid", addresid);
                            return(RedirectToAction("Index", "PayInfo"));
                        }
                    }
                    else
                    {
                        hata = "güvenlik kodunuz yanlış";
                        Session.Add("payeror", hata);
                        Session.Add("addresid", addresid);
                        return(RedirectToAction("Index", "PayInfo"));
                    }
                }
                else
                {
                    hata = "Boş Veya Eksik Kısımlar Bulunmakta";
                    Session.Add("payeror", hata);
                    Session.Add("addresid", addresid);
                    return(RedirectToAction("Index", "PayInfo"));
                }
            }
            else
            {
                return(RedirectToAction("LoginUser", "Home"));
            }
        }
Beispiel #4
0
        public void Execute()
        {
            var id = OrderManagement.AddOrder(new Order(Quantity, Product));

            Console.WriteLine("LOG: Created order for {0}, {1} pieces with an ID {2}", Product, Quantity, id);
        }