示例#1
0
 public ActionResult Add(int id)
 {
     //Sepetimizi Sessionda tutacağız. Burada ki Session adi =Order(Session["Order"]);
     if (Session["Order"] == null)
     {
         if (CheckStock(id, 1) == 0)
         {
             ViewBag.msg = "Yeterli sayida stok yok";
             return(RedirectToAction("ListAllProduct", "Home"));
         }
         ViewBag.msg = "";
         Order o = new Order();
         o.OrderDate = DateTime.Now;
         o.IsPay     = false;
         or.Insert(o);
         Session["Order"] = or.GetLatestObj(1).ProcessResult[0];
         OrderDetail od = new OrderDetail();
         od.OrderId   = ((Order)Session["Order"]).OrderId;
         od.ProductId = id;
         od.Quantity  = 1;
         od.Price     = pr.GetObjById(id).ProcessResult.Price;
         ordrep.Insert(od);
     }
     else
     {
         Order       o      = (Order)Session["Order"];
         OrderDetail Update = ordrep.GetOrderDetByTwoID(o.OrderId, id).ProcessResult;
         if (Update == null)
         {
             if (CheckStock(id, 1) == 0)
             {
                 string msg = "Yeterli sayida stok yok";
                 return(RedirectToAction("ListAllProduct", "Home", new { msg = msg }));
             }
             OrderDetail od = new OrderDetail();
             od.OrderId   = o.OrderId;
             od.ProductId = id;
             od.Quantity  = 1;
             od.Price     = pr.GetObjById(id).ProcessResult.Price;
             ordrep.Insert(od);
         }
         else
         {
             if (CheckStock(id, (int)Update.Quantity + 1) == 0)
             {
                 string msg = "Yeterli sayida stok yok";
                 return(RedirectToAction("ListAllProduct", "Home", new { msg = msg }));
             }
             Update.Quantity++;
             Update.Price += pr.GetObjById(id).ProcessResult.Price;
             ordrep.Update(Update);
         }
     }
     return(RedirectToAction("ListAllProduct", "Home"));
 }
        public ActionResult Pay(Invoice model, List <string> PaymentTypes)
        {
            model.PaymentDate = DateTime.Now;
            foreach (string item in PaymentTypes)
            {
                int PaymentId = Convert.ToInt32(item);
                model.PaymentTypeId = PaymentId;
            }
            model.OrderId = ((Order)Session["Order"]).OrderId;
            InvoiceRep ip = new InvoiceRep();

            if (ip.Insert(model).IsSuccessed)
            {
                List <Product> proList   = new List <Product>();
                Order          ord       = (Order)Session["Order"];
                OrderRep       ordrep    = new OrderRep();
                OrderDetailRep ordDetRep = new OrderDetailRep();
                ProductRep     proRep    = new ProductRep();
                Result <List <OrderDetail> > ordDetRes = ordDetRep.GetListByOrdId((int)model.OrderId);
                foreach (OrderDetail item in ordDetRes.ProcessResult)
                {
                    Product pr = proRep.GetObjById(item.ProductId).ProcessResult;
                    if (pr.Stock != null)
                    {
                        if (pr.Stock < item.Quantity)
                        {
                            string msg = "Yeterli sayida stok yok";
                            return(RedirectToAction("DetailList", "Order", new { msg = msg }));
                        }
                        else
                        {
                            pr.Stock -= item.Quantity;
                            proList.Add(pr);
                        }
                    }
                }
                Member mem = (Member)Session["UserID"];
                if (mem != null)
                {
                    ord.MemberId = mem.UserId;
                    ord.IsPay    = true;
                    ordrep.Update(ord);
                    foreach (Product item in proList)
                    {
                        proRep.Update(item);
                    }
                    Session["Order"] = null;
                    return(RedirectToAction("LatestOrders", "Home"));
                }
                else
                {
                    return(RedirectToAction("SignIn", "Home"));
                }
            }
            else
            {
                return(View(model));
            }
        }
示例#3
0
 public ActionResult Add(int id)
 {
     //Sepetimizi Sessionda tutuyoruz.Burada ki Sessionun Adi=Order(Session[Order])
     if (Session["Order"] == null)
     {
         Order o = new Order();
         o.OrderDate = DateTime.Now;
         o.IsPay     = false;
         or.Insert(o);
         Session["Order"] = or.GetLatestObj(1).ProcessResult[0];
         OrderDetail od = new OrderDetail();
         od.OrderId   = ((Order)Session["Order"]).OrderId;
         od.ProductId = id;
         od.Quantity  = 1;
         od.Price     = pr.GetObjById(id).ProcessResult.Price;
         ordrep.Insert(od);
     }
     else
     {
         Order       o      = (Order)Session["Order"];
         OrderDetail Update = ordrep.GetOrderDetByTwoID(o.OrderId, id).ProcessResult;
         if (Update == null)
         {
             OrderDetail od = new OrderDetail();
             od.OrderId   = o.OrderId;
             od.ProductId = id;
             od.Quantity  = 1;
             od.Price     = pr.GetObjById(id).ProcessResult.Price;
             ordrep.Insert(od);
         }
         else
         {
             Update.Quantity++;
             Update.Price += pr.GetObjById(id).ProcessResult.Price;
             ordrep.Update(Update);
         }
     }
     return(RedirectToAction("ListAllProduct", "Home"));
 }
示例#4
0
        public int CheckStock(int id, int quantity)
        {
            ProductRep pr = new ProductRep();
            Product    p  = pr.GetObjById(id).ProcessResult;

            if (p.Stock != null)
            {
                if (p.Stock < quantity || p.Stock < 0)
                {
                    return(0);
                }
            }
            return(1);
        }
示例#5
0
        public ActionResult Edit(int id)
        {
            ProductViewModel      pwm       = new ProductViewModel();
            List <SelectListItem> CatList   = new List <SelectListItem>();
            List <SelectListItem> BrandList = new List <SelectListItem>();

            foreach (Category item in cr.List().ProcessResult)
            {
                CatList.Add(new SelectListItem {
                    Value = item.CategoryId.ToString(), Text = item.CategoryName
                });
            }
            foreach (Brand item in br.List().ProcessResult)
            {
                BrandList.Add(new SelectListItem {
                    Value = item.BrandId.ToString(), Text = item.BrandName
                });
            }
            pwm.BrandList    = BrandList;
            pwm.CategoryList = CatList;
            pwm.Product      = pr.GetObjById(id).ProcessResult;
            return(View(pwm));
        }
示例#6
0
        public ActionResult Detail(int id)
        {
            Product p = pr.GetObjById(id).ProcessResult;

            return(View(p));
        }