public bool update(m_product ennity) { try { var product = db.m_product.Find(ennity.ID); product.Name = ennity.Name; product.Descreption = ennity.Descreption; product.Image_P = ennity.Image_P; product.Price = ennity.Price; product.ProductPrice = ennity.ProductPrice; product.CatetoryID = ennity.CatetoryID; product.Detail = ennity.Detail; product.CreatedDate = ennity.CreatedDate; product.Status_p = ennity.Status_p; product.Tophot = ennity.Tophot; product.Viewcount = ennity.Viewcount; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public static Responses Delete(int Id) { Responses result = new Responses(); try { using (var db = new MarcomContext()) { m_product m_product = db.m_product.Where(o => o.id == Id).FirstOrDefault(); if (m_product != null) { m_product.is_delete = true; db.SaveChanges(); } } } catch (Exception ex) { result.Message = ex.Message; result.Success = false; } return(result); }
public static bool Insert(VMProduct paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_product a = new m_product(); a.code = paramModel.code; a.name = paramModel.name; a.description = paramModel.description; a.is_delete = paramModel.is_delete; a.created_by = paramModel.created_by; a.created_date = paramModel.created_date; db.m_product.Add(a); db.SaveChanges(); } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
public static bool Delete(VMProduct paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_product a = db.m_product.Where(o => o.id == paramModel.id).FirstOrDefault(); if (a != null) { a.is_delete = true; db.SaveChanges(); } else { result = false; } } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
public ActionResult Create(VMProduct paramModel) { try { ProductRepo.Message = string.Empty; //Create auto generate product_code using (var db = new Markom_IDLEEntities()) { string nol = ""; m_product cek = db.m_product.OrderByDescending(x => x.code).First(); int simpan = int.Parse(cek.code.Substring(3)); simpan++; for (int i = simpan.ToString().Length; i < 4; i++) { nol = nol + "0"; } paramModel.code = "PR" + nol + simpan; } paramModel.created_by = "Administrator"; paramModel.created_date = DateTime.Now; paramModel.is_delete = false; if (null == paramModel.name) { ProductRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali"; } if (string.IsNullOrEmpty(ProductRepo.Message)) { return(Json(new { success = ProductRepo.Insert(paramModel), message = paramModel.code }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = ProductRepo.Message }, JsonRequestBehavior.AllowGet)); } } catch (Exception hasError) { return(Json(new { success = false, message = hasError.Message }, JsonRequestBehavior.AllowGet)); } }
public static bool Update(MProductVM model) { bool res = false; using (AppEntity db = new AppEntity()) { m_product data = db.m_product.Find(model.id); data.code = model.code; data.name = model.name; data.description = model.description; data.updated_by = 1; data.updated_date = DateTime.Now; try { db.SaveChanges(); res = true; } catch (Exception) { throw; } } return(res); }
public static bool Delete(int id) { bool res = false; using (AppEntity db = new AppEntity()) { m_product data = db.m_product.Find(id); data.id = data.id; data.code = data.code; data.name = data.name; data.is_active = false; data.updated_by = 1; data.updated_date = DateTime.Now; try { db.SaveChanges(); res = true; } catch (Exception) { throw; } } return(res); }
public static Responses update(M_ProductViewModel entity) { Responses result = new Responses(); try { using (var db = new MarcomContext()) { if (entity.Id != 0) { m_product m_product = db.m_product.Where(o => o.id == entity.Id).FirstOrDefault(); if (m_product != null) { m_product.code = entity.Code; m_product.name = entity.Name; m_product.description = entity.Description; m_product.is_delete = entity.IsDelete; m_product.updated_by = "David"; m_product.updated_date = DateTime.Now; db.SaveChanges(); } } else { m_product m_product = new m_product(); m_product.code = entity.Code; m_product.name = entity.Name; m_product.description = entity.Description; m_product.is_delete = entity.IsDelete; m_product.created_by = entity.CreatedBy; m_product.created_date = DateTime.Now; db.m_product.Add(m_product); db.SaveChanges(); } } } catch (Exception ex) { result.Message = ex.Message; result.Success = false; } return(result); }
public ActionResult Edit(m_product acc) { if (ModelState.IsValid) { var dao = new ProductDao(); var result = dao.update(acc); if (result) { setAleart("Sửa tài khoản thành công !", "Success"); return(RedirectToAction("Index", "Account")); } else { ModelState.AddModelError("", "Cập nhập không thành công"); } } SetViewBag_Supplier(); return(View()); }
public ActionResult Create(m_product user) { if (ModelState.IsValid) { var dao = new ProductDao(); long id = dao.Insert(user); if (id > 0) { setAleart("Thêm tài khoản thành công !", "Success"); return(RedirectToAction("Index", "Product")); } else { ModelState.AddModelError("", "Thêm user khong thành công"); } } SetViewBag_Supplier(); return(View()); }
public static bool Insert(MProductVM model, string userID) { bool res = false; using (AppEntity db = new AppEntity()) { m_product data = new m_product() { code = model.code, name = model.name, description = model.description, created_by = 1, created_date = DateTime.Now, is_active = true }; db.m_product.Add(data); try { db.SaveChanges(); res = true; } catch (Exception) { throw; } } return(res); }
public static string CreateProduct(ProductViewModel paramDataProd) { string latestSaveCode = string.Empty; using (var db = new MarkomApplicationDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { m_product c = new m_product(); c.code = ProductCode(); c.name = paramDataProd.name; c.description = paramDataProd.description; c.is_delete = paramDataProd.isDelete; c.create_by = paramDataProd.createBy; c.create_date = paramDataProd.createDate; db.m_product.Add(c); db.SaveChanges(); dbContextTransaction.Commit(); //get latest save code latestSaveCode = c.code; } catch (Exception ex) { Message = ex.Message; dbContextTransaction.Rollback(); //throw; } } } return(latestSaveCode); }
public long Insert(m_product login) { db.m_product.Add(login); db.SaveChanges(); return(login.ID); }