public ActionResult DeleteConfirmed(int id) { try { ItemPicture obj = new ItemPicture(); obj.picturelist = db1.Pictures.Where(x => x.ItemID == id).ToList(); for (int i = 0; i < obj.picturelist.Count; i++) { db1.Pictures.Remove(obj.picturelist[i]); } db1.SaveChanges(); if (id != null) { obj.item = db1.Items.Find(id); db1.Items.Remove(obj.item); db1.SaveChanges(); return(RedirectToAction("ItemIndex", new { id = (Convert.ToInt32(TempData["back"])) })); } ViewBag.Message = string.Format("Unable to delete item!"); return(View()); } catch { ViewBag.Message = string.Format("Failed to delete item!"); return(View()); } }
public virtual void InsertItemPicture(ItemPicture itemPicture) { if (itemPicture == null) { throw new ArgumentNullException("itemPicture"); } _itemPictureRepository.Insert(itemPicture); }
public ActionResult ItemDetails(int id) { ItemPicture a = new ItemPicture(); a.item = db.Items.Where(x => x.Id == id).FirstOrDefault(); ViewData["item"] = a.item.Name; a.picturelist = db.Pictures.Where(x => x.ItemID == id).ToList(); return(View(a)); }
public ActionResult Categories(int id) { Category obj = db.Categories.Find(id); ViewData["name"] = obj.Name; ItemPicture a = new ItemPicture(); a.itemlist = db.Items.Where(x => x.CategoryId == id).ToList(); a.picturelist = db.Pictures.Where(x => x.ItemID != null).ToList(); return(View(a)); }
public ActionResult ItemDelete(int id) { ItemPicture a = new ItemPicture(); a.item = db1.Items.Find(id); a.picturelist = db1.Pictures.Where(x => x.ItemID == id).ToList(); if (a.item == null) { return(HttpNotFound()); } return(View(a)); }
public void kepek(ContRepo db) { var kep1 = new ItemPicture(); kep1.ItemId = 1; kep1.Name = "piros-alma.jpg"; db.ItemPictures.Add(kep1); db.SaveChanges(); var kep2 = new ItemPicture(); kep2.ItemId = 1; kep2.Name = "250px-Apple_logo_black.svg.png"; db.ItemPictures.Add(kep2); db.SaveChanges(); var kep3 = new ItemPicture(); kep3.ItemId = 2; kep3.Name = "fbe9e3c3e194988ca1a11d0550412d2b_1140x500_c.jpg"; db.ItemPictures.Add(kep3); db.SaveChanges(); var kep4 = new ItemPicture(); kep4.ItemId = 3; kep4.Name = "korte.jpg"; db.ItemPictures.Add(kep4); db.SaveChanges(); var kep5 = new ItemPicture(); kep5.ItemId = 4; kep5.Name = "323436_640_6_szilva_forras_scholarly__kitchen.jpg"; db.ItemPictures.Add(kep5); db.SaveChanges(); var kep6 = new ItemPicture(); kep6.ItemId = 4; kep6.Name = "bolyhos-agyas-szilva-palinka-1-liter-50-xxl.jpeg"; db.ItemPictures.Add(kep6); db.SaveChanges(); var kep7 = new ItemPicture(); kep7.ItemId = 5; kep7.Name = "116592_eper03-201510171309.jpg"; db.ItemPictures.Add(kep7); db.SaveChanges(); }
public ActionResult ItemIndex(int id) //id is category id { ItemPicture a = new ItemPicture(); a.itemlist = db1.Items.Where(x => x.CategoryId == id).ToList(); Category b = db1.Categories.Find(id); ViewData["shoop"] = b.ShopID; TempData["back"] = id; //for a back from item delete ViewData["CategoryId"] = id; TempData["cid"] = id; return(View(a)); }
public ActionResult AddItem(ItemPicture obj) { using (var transaction = db1.Database.BeginTransaction()) { ViewData["Categoryid"] = TempData["afteradd"]; try { if (ModelState.IsValid) { bool doesExistAlready = db1.Items.Any(o => o.Name == obj.item.Name && o.Description == obj.item.Description); if (!doesExistAlready) { obj.item.CategoryId = Convert.ToInt32(TempData["catid"]); var result0 = db1.Items.Add(obj.item); //int itemid = obj.item.Id; db1.SaveChanges(); if (obj.picture1.ImageFile1 != null) { obj.picture1.picture1 = new byte[obj.picture1.ImageFile1.ContentLength]; obj.picture1.ImageFile1.InputStream.Read(obj.picture1.picture1, 0, obj.picture1.ImageFile1.ContentLength); obj.picture1.ItemID = obj.item.Id; var result3 = db1.Pictures.Add(obj.picture1); db1.SaveChanges(); if (obj.picture2.ImageFile1 != null) { obj.picture2.picture1 = new byte[obj.picture2.ImageFile1.ContentLength]; obj.picture2.ImageFile1.InputStream.Read(obj.picture2.picture1, 0, obj.picture2.ImageFile1.ContentLength); obj.picture2.ItemID = obj.item.Id; var result6 = db1.Pictures.Add(obj.picture2); db1.SaveChanges(); } if (obj.picture3.ImageFile1 != null) { obj.picture3.picture1 = new byte[obj.picture3.ImageFile1.ContentLength]; obj.picture3.ImageFile1.InputStream.Read(obj.picture3.picture1, 0, obj.picture3.ImageFile1.ContentLength); obj.picture3.ItemID = obj.item.Id; var result5 = db1.Pictures.Add(obj.picture3); db1.SaveChanges(); } if (obj.picture4.ImageFile1 != null) { obj.picture4.picture1 = new byte[obj.picture4.ImageFile1.ContentLength]; obj.picture4.ImageFile1.InputStream.Read(obj.picture4.picture1, 0, obj.picture4.ImageFile1.ContentLength); obj.picture4.ItemID = obj.item.Id; var result10 = db1.Pictures.Add(obj.picture4); db1.SaveChanges(); } if (obj.picture5.ImageFile1 != null) { obj.picture5.picture1 = new byte[obj.picture5.ImageFile1.ContentLength]; obj.picture5.ImageFile1.InputStream.Read(obj.picture5.picture1, 0, obj.picture5.ImageFile1.ContentLength); obj.picture5.ItemID = obj.item.Id; var result9 = db1.Pictures.Add(obj.picture5); db1.SaveChanges(); } transaction.Commit(); ViewBag.Message = string.Format("Item is successfully added!"); return(View()); } } else { ViewBag.Message = string.Format("Failed to add item...Item is already exist!"); return(View()); } } ViewBag.Message = string.Format("Failed to add item!"); return(View()); } catch { transaction.Rollback(); return(View()); } } }