public ActionResult Insert(Guid id) { Product gelen = pros.GetByID(id); ProductDetail gelendetay = pds.GetByID(id); ViewBag.SizeToID = new SelectList(ss.GetActive(), "ID", "ProductSize"); ViewBag.ColourID = new SelectList(cs.GetActive(), "ID", "ProductColour"); if (gelen != null && gelendetay == null) { ViewBag.ProductName = gelen.ProductName; return(View()); } ViewBag.ProductName = gelendetay.Product.ProductName; return(View()); }
public JsonResult Insert(Guid id, Guid?productds, string durum) { if (productds != null) { durum = "detay"; } gelen = ps.GetByID(id); if (Session["oturum"] != null) { kullanici = (AppUser)Session["oturum"]; } else if (Session["admin"] != null) { kullanici = (AppUser)Session["admin"]; } if (kullanici != null) { if (scs.Any(m => m.AppUserID == kullanici.ID && m.ProductID == id && m.Status != Core.Entity.Enum.Status.Deleted)) { ShoppingCart guncel = scs.GetByDefault(m => m.AppUserID == kullanici.ID && m.ProductID == id); if (durum == "detay") { guncel.ProductDetailID = (Guid)productds; result = scs.Update(guncel); return(Json(result, JsonRequestBehavior.AllowGet)); } else if (durum == "eksi") { if (guncel.Quantity <= 1) { foreach (ShoppingCart item in scs.GetDefault(m => m.AppUserID == kullanici.ID)) { if (item.ProductID == id) { scs.Remove(item.ID); return(Json(result, JsonRequestBehavior.AllowGet)); } } } guncel.Quantity--; result = scs.Update(guncel); return(Json(result, JsonRequestBehavior.AllowGet)); } else { guncel.Quantity++; result = scs.Update(guncel); return(Json(result, JsonRequestBehavior.AllowGet)); } } else if (scs.Any(m => m.AppUserID == kullanici.ID && m.ProductID == id && m.Status == Core.Entity.Enum.Status.Deleted)) { ShoppingCart guncel = scs.GetByDefault(m => m.AppUserID == kullanici.ID && m.ProductID == id); guncel.Quantity = 1; result = scs.Update(guncel); return(Json(result, JsonRequestBehavior.AllowGet)); } else { ShoppingCart yeni = new ShoppingCart(); if (pds != null) { yeni.ProductDetailID = productds; } yeni.AppUserID = kullanici.ID; yeni.ProductID = gelen.ID; yeni.Name = gelen.ProductName; yeni.Price = gelen.UnitPrice; yeni.Quantity = 1; foreach (ImagePath item in imgs.GetAll()) { if (item.ProductID == gelen.ID) { for (int i = 0; i < 1; i++) { yeni.PicImage = item.ProductImage; } } } result = scs.Add(yeni); return(Json(result, JsonRequestBehavior.AllowGet)); } } if (Session["sepet"] == null) { sepetim = new List <UrunSepeti>(); } else { sepetim = (List <UrunSepeti>)Session["sepet"]; } if (sepetim.Count < 1 || sepetim.FirstOrDefault(m => m.ID == gelen.ID) == null) { UrunSepeti urun = new UrunSepeti(); if (productds != null) { urun.ProductDetailID = (Guid)productds; ProductDetail pdsurun = pds.GetByID(urun.ProductDetailID); urun.ProductColor = pdsurun.Colour.ProductColour; urun.ProductSize = pdsurun.SizeTo.ProductSize; } urun.ID = gelen.ID; urun.ProductName = gelen.ProductName; urun.ProductPrice = gelen.UnitPrice; foreach (ImagePath item in imgs.GetAll()) { if (item.ProductID == gelen.ID) { for (int i = 0; i < 1; i++) { urun.PicImage = item.ProductImage; } } } //urun.ProductColor = gelendetay.Colour.ProductColour; //urun.ProductSize = gelendetay.SizeTo.ProductSize; urun.Quantity = 1; sepetim.Add(urun); result = true; } else { UrunSepeti guncelle = sepetim.FirstOrDefault(m => m.ID == gelen.ID); if (durum == "detay") { guncelle.ProductDetailID = (Guid)productds; ProductDetail pdsurun = pds.GetByID(guncelle.ProductDetailID); guncelle.ProductColor = pdsurun.Colour.ProductColour; guncelle.ProductSize = pdsurun.SizeTo.ProductSize; } else if (durum == "eksi") { if (guncelle.Quantity <= 1) { sepetim = (List <UrunSepeti>)Session["sepet"]; UrunSepeti sil = sepetim.FirstOrDefault(m => m.ID == id); sepetim.Remove(sil); } else { guncelle.Quantity--; } } else { guncelle.Quantity++; } result = true; } Session["sepet"] = sepetim; Session.Timeout = 80; return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult GetOrder(Order item) { bool result; ViewBag.ShipID = new SelectList(shps.GetActive(), "ID", "CompanyName", item.ShipID); ViewBag.ProvinceID = new SelectList(prs.GetActive(), "ID", "Name", item.ProvinceID); ViewBag.RegionToID = new SelectList(rs.GetActive(), "ID", "Name", item.RegionToID); ViewBag.DistrictID = new SelectList(ds.GetActive(), "ID", "Name", item.DistrictID); ViewBag.RoadID = new SelectList(rds.GetActive(), "ID", "Name", item.RoadID); ViewBag.StreetID = new SelectList(strs.GetActive(), "ID", "Name", item.StreetID); ViewBag.BuildID = new SelectList(bs.GetActive(), "ID", "Name", item.BuildID); ViewBag.ProvinceID = new SelectList(prs.GetActive(), "ID", "Name"); List <SelectListItem> lists = new List <SelectListItem>() { new SelectListItem() { Text = "Seçiniz", Value = "0" } }; ViewData["RegionToID"] = lists; ViewData["DistrictID"] = lists; ViewData["RoadID"] = lists; ViewData["StreetID"] = lists; ViewData["BuildID"] = lists; ViewBag.Freight = 5m; List <UrunSepeti> sepet; if (Session["oturum"] != null) { gelen = (AppUser)Session["oturum"]; } else if (Session["admin"] != null) { gelen = (AppUser)Session["admin"]; } else if (Session["sepet"] != null) { Campaing kampanya = new Campaing(); OrderDetail orderDetay = new OrderDetail(); sepet = (List <UrunSepeti>)Session["sepet"]; foreach (UrunSepeti urun in sepet) { Product good = ps.GetByID(urun.ID); ProductDetail goodDetail = pds.GetByID(urun.ProductDetailID); item.AppUserID = good.AppUserID; uyeOlmayan.Name = item.Name; uyeOlmayan.SurName = item.SurName; uyeOlmayan.Phone = item.Phone; uyeOlmayan.EmailAddress = item.EmailAddress; cnms.Add(uyeOlmayan); item.OrderDate = DateTime.Now; item.RequiredDate = DateTime.Now.AddDays(7); os.Add(item); if (ps.Any(m => m.ID == urun.ID)) { if (cams.Any(x => x.ProductID == urun.ID)) { kampanya = cams.GetByDefault(x => x.ProductID == urun.ID); } else { kampanya.Discount = 0f; } goodDetail.UnitInStock -= urun.Quantity; pds.Update(goodDetail); orderDetay.ProductID = good.ID; orderDetay.OrderID = item.ID; orderDetay.Quantity = urun.Quantity; orderDetay.Price = (good.UnitPrice - (good.UnitPrice * (decimal)kampanya.Discount)) * orderDetay.Quantity; ods.Add(orderDetay); } } Session.Remove("sepet"); TempData["siparis"] = "Siparişiniz alındı"; return(RedirectToAction("Index", "ShoppingCart")); } if (gelen != null) { List <ShoppingCart> urunler = scs.GetDefault(m => m.AppUserID == gelen.ID && m.Status != Core.Entity.Enum.Status.Deleted); Campaing kampanya = new Campaing(); OrderDetail orderDetay = new OrderDetail(); foreach (ShoppingCart urun in urunler) { Product good = ps.GetByID(urun.ProductID); item.AppUserID = good.AppUserID; item.Name = gelen.Name; item.SurName = gelen.SurName; item.Phone = gelen.Phone; item.EmailAddress = gelen.EmailAddress; item.OrderDate = DateTime.Now; item.RequiredDate = DateTime.Now.AddDays(7); os.Add(item); if (cams.Any(x => x.ProductID == urun.ProductID)) { kampanya = cams.GetByDefault(x => x.ProductID == urun.ProductID); indirim = (float)kampanya.Discount; } else { indirim = 0f; } ProductDetail goodDetail = pds.GetByID((Guid)urun.ProductDetailID); goodDetail.UnitInStock -= urun.Quantity; pds.Update(goodDetail); orderDetay.AppUserID = gelen.ID; orderDetay.ProductID = good.ID; orderDetay.OrderID = item.ID; orderDetay.Quantity = urun.Quantity; orderDetay.Price = (good.UnitPrice - (good.UnitPrice * (decimal)indirim)) * orderDetay.Quantity; ods.Add(orderDetay); scs.Remove(urun.ID); } TempData["siparis"] = "Siparişiniz alındı"; return(RedirectToAction("Index", "ShoppingCart")); } return(View()); }