public IHttpActionResult DeleteGanWu([FromUri]long id) { var result = false; var ganWu = new Zs_GanWu(); var dic = new Dictionary<string, string>(); ganWu = bGanWu.Find(id); if (ganWu == null) return NotFound(); //删除感悟 result = bGanWu.Delete(ganWu); //实体列表 var ganWuAttList = bGanWuAtt.Entities.Where(f => f.GWID == ganWu.GwID); //遍历删除本地资源 foreach (var item in ganWuAttList) sysFun.DeleteFile(item.AttType, item.AttUrl); //批量删除 if (ganWuAttList.Count() > 0) bGanWuAtt.Delete(ganWuAttList); if (result) { dic.Add("result", "1"); return Ok(dic); } else { dic.Add("result", "0"); return Ok(); } }
public IHttpActionResult AddGanWu(AddGanWuModel model) { var ganWu = new Zs_GanWu(); var result = new GanWuViewModel(); if (!ModelState.IsValid) return BadRequest(ModelState); //初始化实体 ganWu = sysFun.InitialEntity<AddGanWuModel, Zs_GanWu>(model, ganWu); //添加事历 ganWu = bGanWu.Add(ganWu); //更新附件列表 result = UpdateAttList(ganWu); if (ganWu.GwID > 0) { return Ok(result); } else { return Ok("添加失败"); } }
public ActionResult GanWuCreate(GanWuCreate model) { if (!ModelState.IsValid) return View(model); var item = new Zs_GanWu(); item = SysFun.Instance.InitialEntity<GanWuCreate, Zs_GanWu>(model, item); item.UpdateDate = DateTime.Now; item = bGanWu.Add(item); if (item.GwID > 0) return RedirectToAction("GanWuList"); return View(model); }
/// <summary> /// 更新附件列表 /// </summary> /// <param name="ganWu"></param> private GanWuViewModel UpdateAttList(Zs_GanWu ganWu) { var result = new GanWuViewModel(); //实体列表 var ganWuAttList = bGanWuAtt.Entities.Where(f => f.CreateDate < ganWu.CreateDate && f.GWID == 0); //遍历删除本地资源 foreach (var item in ganWuAttList) sysFun.DeleteFile(item.AttType, item.AttUrl); //批量删除 if (ganWuAttList.Count() > 0) bGanWuAtt.Delete(ganWuAttList); //批量更新 bGanWuAtt.Update(f => f.MID == ganWu.MID, f => new Zs_GanWuAtt { GWID = ganWu.GwID }); //实体列表 ganWuAttList = bGanWuAtt.Entities.Where(f => f.MID == ganWu.MID); result.GanWu = ganWu; result.GanWuAtt = ganWuAttList.ToList(); return result; }
public IHttpActionResult UpdateGanWu(UpdateGanWuModel model) { var ganWu = new Zs_GanWu(); var result = new GanWuViewModel(); if (!ModelState.IsValid) return BadRequest(ModelState); //初始化实体 ganWu = bGanWu.Find(model.GwID); ganWu = sysFun.InitialEntity<UpdateGanWuModel, Zs_GanWu>(model, ganWu); //更新事历 ganWu = bGanWu.UpdateEntity(ganWu); //更新附件列表 result = UpdateAttList(ganWu); return Ok(result); }
public IHttpActionResult GetGanWuById([FromUri]long id) { var ganWu = new Zs_GanWu(); var ganWuAtt = new List<Zs_GanWuAtt>(); var result = new GanWuViewModel(); ganWu = bGanWu.Find(id); ganWuAtt = bGanWuAtt.Entities.Where(f => f.GWID == ganWu.GwID).ToList(); result.GanWu = ganWu; result.GanWuAtt = ganWuAtt; return Ok(result); }