public ViewResult Edit(string id, string view) { Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); var model = default(CheckRecordEntity); ViewBag.id = id; ViewBag.deptid = user.DeptId; ViewBag.view = view; if (string.IsNullOrEmpty(id)) { model = new CheckRecordEntity() { CheckTime = DateTime.Now, CheckUser = user.UserName, CheckItems = new List <CheckItemEntity>() }; } else { var bll = new CheckRecordBLL(); model = bll.GetDetail(id); } ViewBag.json = Newtonsoft.Json.JsonConvert.SerializeObject(model.CheckItems); DataItemDetailBLL dataitembll = new DataItemDetailBLL(); var list1 = dataitembll.GetDataItemListByItemCode("预警指标卡类别"); var data1 = list1.Select(x => new SelectListItem() { Value = x.ItemValue, Text = x.ItemName }); ViewData["Category"] = data1; return(View(model)); }
public JsonResult Edit(string id, CheckRecordEntity model) { Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); if (string.IsNullOrEmpty(id)) { model.CheckRecordId = Guid.NewGuid().ToString(); } else { model.CheckRecordId = id; } model.CreateUserId = model.ModifyUserId = user.UserId; model.CreateTime = model.ModifyTime = DateTime.Now; model.DeptId = user.DeptId; model.DeptName = user.DeptName; if (model.CheckItems == null) { model.CheckItems = new List <CheckItemEntity>(); } foreach (var item in model.CheckItems) { if (string.IsNullOrEmpty(item.CheckItemId)) { item.CheckItemId = Guid.NewGuid().ToString(); } item.CreateUserId = item.ModifyUserId = user.UserId; item.CreateTime = item.ModifyTime = DateTime.Now; item.CheckRecordId = model.CheckRecordId; } var success = true; var message = "保存成功!"; var bll = new CheckRecordBLL(); try { bll.Save(model); } catch (Exception e) { success = false; message = e.Message; } return(Json(new { success, message })); }
public void Save(CheckRecordEntity model) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var entity = (from q in db.IQueryable <CheckRecordEntity>() where q.CheckRecordId == model.CheckRecordId select q).FirstOrDefault(); foreach (var item in model.CheckItems) { var fileentities = (from q in db.IQueryable <FileInfoEntity>() where q.RecId == item.clientid select q).ToList(); fileentities.ForEach(x => x.RecId = item.CheckItemId); db.Update(fileentities); } if (entity == null) { db.Insert(model); db.Insert(model.CheckItems); if (model.Files != null) { db.Insert(model.Files); } } else { entity.CardId = model.CardId; entity.CardName = model.CardName; entity.CheckPlace = model.CheckPlace; entity.ModifyTime = model.ModifyTime; entity.ModifyUserId = model.ModifyUserId; entity.CheckUser = model.CheckUser; entity.CheckTime = model.CheckTime; entity.Category = model.Category; entity.CheckPlace = model.CheckPlace; db.Update(entity); var contents = (from q in db.IQueryable <CheckItemEntity>() where q.CheckRecordId == model.CheckRecordId select q).ToList(); var deleteitems = contents.Where(x => !model.CheckItems.Any(y => y.CheckItemId == x.CheckItemId)).ToList(); db.Delete(deleteitems); foreach (var item in model.CheckItems) { var ss = contents.Find(x => x.CheckItemId == item.CheckItemId); if (ss == null) { db.Insert(item); } else { ss.CheckContentId = item.CheckContentId; ss.CheckContent = item.CheckContent; ss.Num1 = item.Num1; ss.Num2 = item.Num2; ss.Num3 = item.Num3; ss.Num4 = item.Num4; ss.Dangerous = item.Dangerous; ss.Measures = item.Measures; ss.Dangerous2 = item.Dangerous2; ss.Measures2 = item.Measures2; ss.ModifyTime = item.ModifyTime; ss.ModifyUserId = item.ModifyUserId; db.Update(ss); } } } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
public void Save(CheckRecordEntity model) { this.service.Save(model); }