public bool AddTypeProduct(type_products TypeProduct) { try { db.type_products.Add(TypeProduct); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult AddTypeProduct(type_products TypeProduct) { if (ModelState.IsValid) { TypeProduct.created_at = DateTime.Now; var dao = new TypeProductDao(); var model = dao.AddTypeProduct(TypeProduct); TempData["success"] = "Add Success"; return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Fail"); return(RedirectToAction("Index")); } }
public ActionResult EditTypeProduct(type_products TypeProduct) { if (ModelState.IsValid) { var dao = new TypeProductDao(); var CreatedAt = dao.GetTypeProduct(TypeProduct.id).created_at; TypeProduct.created_at = CreatedAt; TypeProduct.updated_at = DateTime.Now; dao.EditTypeProduct(TypeProduct); TempData["success"] = "Edited Successfully"; return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Fail Edit"); return(View("Index")); } }
public bool EditTypeProduct(type_products TypeProduct) { try { type_products pro = db.type_products.Find(TypeProduct.id); pro.name = TypeProduct.name; pro.description = TypeProduct.description; pro.image = TypeProduct.image; pro.created_at = TypeProduct.created_at; pro.updated_at = TypeProduct.updated_at; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }