//[ValidateAntiForgeryToken] public JsonResult DeleteItemAll(int id) { var _qry = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == id) select new asset_warrantyViewModel() { warranty_id = aw.warranty_id }).ToList <asset_warrantyViewModel>(); if (_qry != null) { foreach (asset_warrantyViewModel ass_wrt in _qry) { tr_asset_warranty tr_asset_warranty = db.tr_asset_warranty.Find(ass_wrt.warranty_id); if (tr_asset_warranty != null) { tr_asset_warranty.fl_active = false; tr_asset_warranty.deleted_by = UserProfile.UserId; tr_asset_warranty.deleted_date = DateTime.Now; db.Entry(tr_asset_warranty).State = EntityState.Modified; db.SaveChanges(); } } return(Json(1, JsonRequestBehavior.AllowGet)); } else { return(Json(0, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteConfirmed(int id) { tr_asset_warranty tr_asset_warranty = db.tr_asset_warranty.Find(id); db.tr_asset_warranty.Remove(tr_asset_warranty); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "warranty_id,asset_id,warranty_number,warranty_item_name,warranty_date,warranty_exp_date,warranty_description,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_asset_warranty tr_asset_warranty) { if (ModelState.IsValid) { db.Entry(tr_asset_warranty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_asset_warranty)); }
public ActionResult Edit([Bind(Include = "warranty_id, asset_parent_id, warranty_number, warranty_item_name, warranty_date, warranty_exp_date, warranty_description")] asset_warrantyViewModel asset_wrt) { if (asset_wrt.warranty_date > DateTime.Today) { ModelState.AddModelError("warranty_date", "Please enter a valid date."); } if (asset_wrt.warranty_date > asset_wrt.warranty_exp_date) { ModelState.AddModelError("warranty_exp_date", "Warranty expired date must be after warranty date."); } if (ModelState.IsValid && asset_wrt.warranty_id > 0) { tr_asset_warranty ass_warranty = db.tr_asset_warranty.Find(asset_wrt.warranty_id); ass_warranty.warranty_number = asset_wrt.warranty_number; ass_warranty.warranty_item_name = asset_wrt.warranty_item_name; ass_warranty.warranty_date = asset_wrt.warranty_date; ass_warranty.warranty_exp_date = asset_wrt.warranty_exp_date; ass_warranty.warranty_description = asset_wrt.warranty_description; ass_warranty.fl_active = true; ass_warranty.updated_date = DateTime.Now; ass_warranty.updated_by = UserProfile.UserId; ass_warranty.deleted_date = null; ass_warranty.deleted_by = null; ass_warranty.org_id = UserProfile.OrgId; db.Entry(ass_warranty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } tr_asset_registration ass_reg = db.tr_asset_registration.Find(asset_wrt.asset_parent_id); asset_wrt.FormMode = EnumFormModeKey.Form_Edit; asset_wrt.asset_parent_id = (int)ass_reg.asset_id; asset_wrt.asset_parent = ass_reg; ms_vendor msvendor = db.ms_vendor.Find(ass_reg.vendor_id); asset_wrt.vendor_name = msvendor.vendor_name; //Data view edit asset_wrt.asset_warranty_list = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == asset_wrt.asset_parent_id) select aw).ToList <tr_asset_warranty>(); return(View(asset_wrt)); }
// GET: asset_warranty/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tr_asset_warranty tr_asset_warranty = db.tr_asset_warranty.Find(id); if (tr_asset_warranty == null) { return(HttpNotFound()); } return(View(tr_asset_warranty)); }
// GET: asset_warranty/Edit/5 public ActionResult Edit(int?id, int?idw) { if (id == null || idw == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tr_asset_registration ass_reg = db.tr_asset_registration.Find(id); if (ass_reg == null) { return(HttpNotFound("Assset not found.")); } asset_warrantyViewModel asset_model = new asset_warrantyViewModel() { FormMode = EnumFormModeKey.Form_Edit, asset_parent_id = (int)ass_reg.asset_id, asset_parent = ass_reg }; tr_asset_warranty ass_warranty = db.tr_asset_warranty.Find(idw); if (ass_warranty != null) { asset_model.warranty_id = ass_warranty.warranty_id; asset_model.warranty_number = ass_warranty.warranty_number; asset_model.warranty_item_name = ass_warranty.warranty_item_name; asset_model.warranty_date = ass_warranty.warranty_date; asset_model.warranty_exp_date = ass_warranty.warranty_exp_date; asset_model.warranty_description = ass_warranty.warranty_description; } ms_vendor msvendor = db.ms_vendor.Find(ass_reg.vendor_id); asset_model.vendor_name = msvendor.vendor_name; //Data view edit asset_model.asset_warranty_list = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == id) select aw).ToList <tr_asset_warranty>(); return(View(asset_model)); }
//[ValidateAntiForgeryToken] public JsonResult DeleteItem(int id) { tr_asset_warranty tr_asset_warranty = db.tr_asset_warranty.Find(id); if (tr_asset_warranty != null) { tr_asset_warranty.fl_active = false; tr_asset_warranty.deleted_by = UserProfile.UserId; tr_asset_warranty.deleted_date = DateTime.Now; db.Entry(tr_asset_warranty).State = EntityState.Modified; db.SaveChanges(); return(Json(1, JsonRequestBehavior.AllowGet)); } else { return(Json(0, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create([Bind(Include = "asset_parent_id, warranty_number, warranty_item_name, warranty_date, warranty_exp_date, warranty_description")] asset_warrantyViewModel asset_wrt) { try { if (asset_wrt.warranty_date > DateTime.Today) { ModelState.AddModelError("warranty_date", "Please enter a valid date."); } if (asset_wrt.warranty_date > asset_wrt.warranty_exp_date) { ModelState.AddModelError("warranty_exp_date", "Warranty expired date must be after warranty date."); } tr_asset_warranty existWarranty = (from exw in db.tr_asset_warranty.Where(exw => exw.warranty_number == asset_wrt.warranty_number && exw.asset_id == asset_wrt.asset_parent_id) select exw).FirstOrDefault <tr_asset_warranty>(); if (existWarranty == null) { if (ModelState.IsValid) { tr_asset_warranty ass_warranty = new tr_asset_warranty(); ass_warranty.asset_id = asset_wrt.asset_parent_id; ass_warranty.warranty_number = asset_wrt.warranty_number; ass_warranty.warranty_item_name = asset_wrt.warranty_item_name; ass_warranty.warranty_date = asset_wrt.warranty_date; ass_warranty.warranty_exp_date = asset_wrt.warranty_exp_date; ass_warranty.warranty_description = asset_wrt.warranty_description; ass_warranty.fl_active = true; ass_warranty.created_date = DateTime.Now; ass_warranty.created_by = UserProfile.UserId; ass_warranty.updated_date = DateTime.Now; ass_warranty.updated_by = UserProfile.UserId; ass_warranty.deleted_date = null; ass_warranty.deleted_by = null; ass_warranty.org_id = UserProfile.OrgId; ass_warranty = db.tr_asset_warranty.Add(ass_warranty); db.SaveChanges(); ModelState.Clear(); asset_wrt.warranty_number = string.Empty; asset_wrt.warranty_item_name = string.Empty; asset_wrt.warranty_date = null; asset_wrt.warranty_exp_date = null; } } else { //Data view List <tr_asset_warranty> assetwrtlist = asset_wrt.asset_warranty_list = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == asset_wrt.asset_parent_id) select aw).ToList <tr_asset_warranty>(); ModelState.Clear(); asset_wrt = new asset_warrantyViewModel(); asset_wrt.asset_warranty_list = assetwrtlist; return(View(asset_wrt)); } //Data view asset_wrt.asset_warranty_list = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == asset_wrt.asset_parent_id) select aw).ToList <tr_asset_warranty>(); } catch (Exception ex) { string msgErr = string.Format("An unknown error has occurred , Please contact your system administrator. {0}", ex.Message); if (ex.InnerException != null) { msgErr += string.Format(" Inner Exception: {0}", ex.InnerException.Message); } ModelState.AddModelError("", msgErr); } return(View(asset_wrt)); }