public ActionResult Create(Product Object,string CategoryName) { try { HttpPostedFileBase anh = HttpContext.Request.Files["MyImage"]; byte[] MyImage = new byte[anh.ContentLength]; anh.InputStream.Read(MyImage, 0, anh.ContentLength); Object.Image = MyImage; if (CategoryName == "Khong Co") Object.CategoryID = 0; else Object.CategoryID = new Shop.Models.DataModel.ProductCategoryModels().GetIdByName(CategoryName); Object.CreateBy = new Shop.Models.DataModel.AdminModels().GetIdByUserName(Session[Shop.Models.SupportModel.SessionKey.LogIn] as string); Object.CreateDate = DateTime.Now; Object.EditBy = new Shop.Models.DataModel.AdminModels().GetIdByUserName(Session[Shop.Models.SupportModel.SessionKey.LogIn] as string); Object.EditDate = DateTime.Now; bool check = new ProductModels().Add(Object); if (check) return RedirectToAction("Index"); else return View(); } catch { return View(); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here var check = new ProductModels().Delete(id); if (check) return RedirectToAction("Index"); else return View(); } catch { return View(); } }