public ActionResult AddCustomData(string CustomName, string CustomValue) { this.Internationalization(); TugDataEntities db = new TugDataEntities(); try { System.Linq.Expressions.Expression<Func<CustomField, bool>> exp = u => u.CustomName == CustomName && u.CustomLabel == CustomValue; CustomField tmpCustom = db.CustomField.Where(exp).FirstOrDefault(); if (tmpCustom != null) { throw new Exception(CustomValue + "已存在!"); } CustomField custom = new CustomField(); custom.CustomName = CustomName; custom.CustomValue = ""; custom.CustomLabel = CustomValue; custom.Description = ""; custom.UserID = Session.GetDataFromSession<int>("userid"); custom.CreateDate = custom.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); custom = db.CustomField.Add(custom); db.SaveChanges(); return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); } catch (Exception ex) { throw ex; } }
public ActionResult AddEdit() { this.Internationalization(); //int idx = Util.toint(Request.Form["IDX"]); //Fuelprice price = db.Fuelprice.Where(u => u.IDX == idx).FirstOrDefault(); #region Add if (Request.Form["oper"].Equals("add")) { string CustomName = Request.Form["CustomName"].Trim(); string CustomValue = Request.Form["CustomLabel"].Trim(); try { TugDataEntities db = new TugDataEntities(); { TugDataModel.CustomField custom = new CustomField(); custom.CustomName = CustomName; custom.CustomValue = ""; custom.CustomLabel = CustomValue; custom.Description = ""; custom.UserID = Session.GetDataFromSession<int>("userid"); custom.CreateDate = custom.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd"); custom = db.CustomField.Add(custom); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; return Json(ret); } } catch (Exception) { var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //Response.Write(@Resources.Common.EXCEPTION_MESSAGE); return Json(ret); } } #endregion Add #region Edit if (Request.Form["oper"].Equals("edit")) { try { TugDataEntities db = new TugDataEntities(); int idx = Util.toint(Request.Form["IDX"]); CustomField customedit = db.CustomField.Where(u => u.IDX == idx).FirstOrDefault(); string oldLocation = customedit.CustomLabel; string newLocation = Request.Form["CustomLabel"].Trim(); string CustomName = customedit.CustomName; string CustomValue = Request.Form["CustomLabel"].Trim(); CustomField custom = db.CustomField.Where(u => u.CustomName == CustomName && u.CustomLabel==CustomValue).FirstOrDefault(); if (custom != null) { throw new Exception(CustomValue + "已存在!"); } else { customedit.CustomLabel = CustomValue; customedit.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd"); customedit.UserID = Session.GetDataFromSession<int>("userid"); db.Entry(customedit).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var list = db.OrderService.Where(u => u.ServiceWorkPlace.Trim().ToLower() == oldLocation.Trim().ToLower()).Select(u => u).ToList(); if (list != null) { foreach (var item in list) { item.ServiceWorkPlace = newLocation.Trim(); db.Entry(item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); } } catch (Exception ex) { throw ex; } } #endregion Edit return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); }