Beispiel #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"));
 }
Beispiel #2
0
        public ActionResult Add(int id)
        {
            int memberId = 0;

            foreach (Member item in mr.List().ProcessResult)
            {
                if (item.FirstName == User.Identity.Name)
                {
                    memberId = item.UserId;
                    break;
                }
            }
            //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;

                if (memberId != 0)
                {
                    o.MemberId = memberId;
                }

                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("Index", "Home"));
        }
        // GET: Order
        public ActionResult Add(int id, ProductViewModel model)
        {
            //sepetimizi session da tutuyoruz buradaki sessionun adı order(session)[order])
            if (Session["Order"] == null)
            {
                Order o = new Order();
                o.OrderDate = DateTime.Now;
                o.MemberId  = int.Parse(User.Identity.Name);
                o.IsPay     = false;
                or.Insert(o);
                Session["Order"] = or.GetLastersObj(1).ProcessResult[0];
                OrderDetail od = new OrderDetail();
                od.OrderId   = ((Order)Session["Order"]).OrderId;
                od.ProductId = id;
                Product stok = pr.GetObjById(od.ProductId).ProcessResult;
                stok.Stock--;
                pr.Update(stok);
                od.Quantity = 1;
                od.Price    = pr.GetObjById(id).ProcessResult.Price;

                //od.Product.Stock -= pr.GetObjById(id).ProcessResult.Stock;
                //rp.resultint = pr.Update(model.Product);

                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;
                    Product stok = pr.GetObjById(od.ProductId).ProcessResult;
                    stok.Stock--;
                    pr.Update(stok);
                    od.Price = pr.GetObjById(id).ProcessResult.Price;
                    ordrep.Insert(od);
                }
                else
                {
                    Product stok = pr.GetObjById(update.ProductId).ProcessResult;
                    stok.Stock--;
                    pr.Update(stok);
                    update.Quantity++;
                    update.Price += pr.GetObjById(id).ProcessResult.Price;
                    ordrep.Update(update);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Add(int id)
        {
            if (HttpContext.Request.Cookies["UserLogin"] != null)
            {
                ViewBag.CurrentUser = HttpContext.Request.Cookies["UserLogin"].Value;
            }
            //Sepetimizi sessionda tutuyoruz. Burada ki Sessionun adi:Order(Session[Order])
            if (Session["Order"] == null)
            { //Order isimli sessiona bir adet Order ekledik
                Order o = new Order();
                o.OrderDate = DateTime.Now;
                o.IsPay     = false;
                or.Insert(o);
                //OrderRepository içerisinden son create edilmiş bir orderi Session uzerinde tutup o yapıya order Detail ekliyoruz
                Session["Order"] = or.GetLatestObj(1).ProcessResult[0];
                OrderDetail od = new OrderDetail();
                od.OrderId   = ((Order)Session["Order"]).OrderId;
                od.ProductId = id;

                //OrderDetail içerisinde quantity ve pricei guncelliyoruz.
                od.Quantity = 1;
                od.Price    = pr.GetObjById(id).ProcessResult.Price;
                o.MemberId  = Convert.ToInt32(Request.Cookies["UserId"].Value);
                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("Index", "Home"));
        }
 // GET: Order
 public ActionResult Add(int id)
 {
     if (Session["Order"] == null)
     {
         Order o = new Order();
         o.OrderDate = DateTime.Now;
         o.IsPay     = false;
         if (Session["CurrentUser"] != null)
         {
             Member m = (Member)Session["CurrentUser"];
             o.MemberID = m.UserID;
         }
         or.Insert(o);
         Session["Order"] = or.GetLatestObj(1).ProccessResult[0];
         OrderDetail od = new OrderDetail();
         od.OrderID   = ((Order)Session["Order"]).OrderID;
         od.ProductID = id;
         od.Quantity  = 1;
         od.Price     = pr.GetById(id).ProccessResult.Price;
         ordrep.Insert(od);
     }
     else
     {
         Order       o      = (Order)Session["Order"];
         OrderDetail update = ordrep.GetOrdByTwoId(o.OrderID, id).ProccessResult;
         if (update == null)
         {
             OrderDetail ord = new OrderDetail();
             ord.OrderID   = o.OrderID;
             ord.ProductID = id;
             ord.Quantity  = 1;
             ord.Price     = pr.GetById(id).ProccessResult.Price;
             ordrep.Insert(ord);
         }
         else
         {
             update.Quantity++;
             update.Price += pr.GetById(id).ProccessResult.Price;
             ordrep.Update(update);
         }
     }
     return(RedirectToAction("Index", "Home"));
 }
Beispiel #6
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"));
 }