public ActionResult Create(string moduleCode = "None") { if (string.IsNullOrWhiteSpace(moduleCode)) { moduleCode = "None"; } CommonCommentBiz.ModuleCode = moduleCode.ToEnum(CommonCommentModuleCodeEnum.None); CommonComment entity = null; if (CommonCommentBiz.ModuleCode != CommonCommentModuleCodeEnum.None) { //如果是非列表模块, 则要到数据库取值 if (!ListCommonCommentBiz.CodeList.Contains(CommonCommentBiz.ModuleCode.ToString())) { entity = CommonCommentBiz.GetByCode(moduleCode); } if (null == entity) { entity = new CommonComment { ModuleCode = moduleCode }; } } else { SetMessage("模块代码错误!"); entity = new CommonComment(); } return View(entity); }
public override CommonComment Add(CommonComment entity) { using (var db = new Entities()) { if (CheckCommonComment(entity, db) && CodeList.Contains(ModuleCode.ToString())) { var date = DateTime.Now; var userId = CurrentUserBiz.CurrentUser.ID; entity.CreateDate = date; entity.CreateUserID = userId; entity.ModifyDate = date; entity.ModifyUserID = userId; entity.DiscussDate = date; entity.DiscussUserID = userId; entity.ModuleCode = ModuleCode.ToString(); db.CommonComment.Add(entity); Errors = db.GetErrors(); if (!HasError) { db.SaveChanges(); } } return entity; } }
public ActionResult Create(CommonComment entity) { if (string.IsNullOrWhiteSpace(entity.ModuleCode)) { entity.ModuleCode = "None"; } CommonCommentBiz.ModuleCode = entity.ModuleCode.ToEnum(CommonCommentModuleCodeEnum.None); if (CommonCommentBiz.ModuleCode != CommonCommentModuleCodeEnum.None) { if (!ListCommonCommentBiz.CodeList.Contains(entity.ModuleCode)) { if (entity.ID == 0) { CommonCommentBiz.Add(entity); } else { CommonCommentBiz.Edit(entity); } } else { ListCommonCommentBiz.ModuleCode = CommonCommentBiz.ModuleCode; if (entity.ID == 0) { ListCommonCommentBiz.Add(entity); } else { ListCommonCommentBiz.Edit(entity); } } if (!CommonCommentBiz.HasError && !ListCommonCommentBiz.HasError) { SetMessage("保存成功!"); if (entity.ID > 0) { entity = CommonCommentBiz.GetByCode(entity.ModuleCode); } } else { ParseBizError(CommonCommentBiz); ParseBizError(ListCommonCommentBiz); } } else { SetMessage("模块代码错误!"); } return View(entity); }
public virtual CommonComment Add(CommonComment entity) { using (var db = new Entities()) { if (!string.IsNullOrEmpty(ModuleCode.ToString())) { if (db.CommonComment.Any(q => q.ModuleCode.ToUpper() == ModuleCode.ToString().ToUpper())) { Errors.Set("Error", "该模块已经有数据!"); } else if (entity.DiscussType == (int)DiscussTypeEnum.Edit && string.IsNullOrWhiteSpace(entity.DiscussContent)) { Errors.Set("Error", "内容必须填写!"); } else if (entity.DiscussType == (int)DiscussTypeEnum.Upload && (string.IsNullOrWhiteSpace(entity.DiscussFileUrl) || string.IsNullOrWhiteSpace(entity.DiscussOfficeFileUrl))) { Errors.Set("Error", "必须上传文件!"); } else { var nowDate = DateTime.Now; var userId = CurrentUserBiz.CurrentUser.ID; entity.CreateDate = nowDate; entity.CreateUserID = userId; entity.ModifyDate = nowDate; entity.ModifyUserID = userId; entity.ModuleCode = ModuleCode.ToString(); entity.DiscussDate = nowDate; entity.DiscussUserID = userId; db.CommonComment.Add(entity); Errors = db.GetErrors(); if (!HasError) { db.SaveChanges(); } } } return entity; } }
public virtual CommonComment Edit(CommonComment entity) { using (var db = new Entities()) { if (db.CommonComment.Any(q => q.ID != entity.ID && q.ModuleCode.ToUpper() == entity.ModuleCode.ToUpper())) { Errors.Set("Error", "保存错误!模块代码不符!"); } else { entity.ModifyDate = DateTime.Now; entity.ModifyUserID = CurrentUserBiz.CurrentUser.ID; entity.DiscussUserID = CurrentUserBiz.CurrentUser.ID; var entry = db.Entry(entity); entry.State = EntityState.Unchanged; entry.Property(q => q.ModifyDate).IsModified = true; entry.Property(q => q.ModifyUserID).IsModified = true; entry.Property(q => q.DiscussType).IsModified = true; if (entity.DiscussType == (int)DiscussTypeEnum.Edit) { entry.Property(q => q.DiscussContent).IsModified = true; } else { entry.Property(q => q.DiscussFileUrl).IsModified = true; entry.Property(q => q.DiscussOfficeFileUrl).IsModified = true; } entry.Property(q => q.DiscussUserID).IsModified = true; Errors = db.GetErrors(); if (!HasError) { db.SaveChanges(); } } return entity; } }
public bool CheckCommonComment(CommonComment entity, Entities db) { if (entity.DiscussType == (int)DiscussTypeEnum.Edit && string.IsNullOrWhiteSpace(entity.DiscussContent)) { Errors.Set("Error", "发布内容不能为空"); } else if (entity.DiscussType == (int)DiscussTypeEnum.Upload && string.IsNullOrWhiteSpace(entity.DiscussFileUrl)) { Errors.Set("Error", "发布文件必须上传!"); } else if(string.IsNullOrWhiteSpace(entity.DiscussTitle)) { Errors.Set("Errors", "标题不能为空!"); } else { return true; } return false; }
public override CommonComment Edit(CommonComment entity) { using (var db = new Entities()) { if (CheckCommonComment(entity, db) && CodeList.Contains(ModuleCode.ToString())) { var date = DateTime.Now; var userId = CurrentUserBiz.CurrentUser.ID; entity.ModifyDate = date; entity.ModifyUserID = userId; entity.DiscussDate = date; var entry = db.Entry(entity); entry.State = EntityState.Unchanged; entry.Property(q => q.ModifyDate).IsModified = true; entry.Property(q => q.ModifyUserID).IsModified = true; entry.Property(q => q.DiscussDate).IsModified = true; entry.Property(q => q.DiscussType).IsModified = true; entry.Property(q => q.DiscussTitle).IsModified = true; entry.Property(q => q.DiscussContent).IsModified = true; entry.Property(q => q.DiscussFileUrl).IsModified = true; entry.Property(q => q.DiscussOfficeFileUrl).IsModified = true; entry.Property(q => q.DiscussUserID).IsModified = true; Errors = db.GetErrors(); if (!HasError) { db.SaveChanges(); } } return entity; } }
public ActionResult Edit(long id, string moduleCode = "None") { if (string.IsNullOrWhiteSpace(moduleCode)) { moduleCode = "None"; } ListCommonCommentBiz.ModuleCode = moduleCode.ToEnum(CommonCommentModuleCodeEnum.None); CommonComment entity = null; if (ListCommonCommentBiz.ModuleCode != CommonCommentModuleCodeEnum.None && ListCommonCommentBiz.CodeList.Contains(ListCommonCommentBiz.ModuleCode.ToString())) { entity = ListCommonCommentBiz.GetById(id); if (null == entity || (null != entity && entity.ModuleCode != ListCommonCommentBiz.ModuleCode.ToString())) { SetMessage("模块代码错误!"); entity = new CommonComment(); } if (null == entity) { entity = new CommonComment() { ModuleCode = moduleCode }; } } else { SetMessage("模块代码错误!"); entity = new CommonComment(); } return View("Create", entity); }