public JsonResult NoticeInfoCreate(int? platformType, string subject, string nContent, DateTime beginDate, DateTime endDate, bool? isTop, string rightBranch, string remark) { var strMessage = "操作失败!"; try { var addModel = new Notice() { NContent = nContent, Subject = subject, //OrderNum = model.OrderNum, IsTop = isTop, BeginDate = CommonHelper.To<DateTime>(beginDate), EndDate = CommonHelper.To<DateTime>(endDate), OrderNum = 0, Remark = remark, CreateBy = LoginUserManager.CurrLoginUser.UserId, CreateTime = DateTime.Now, UpdateBy = LoginUserManager.CurrLoginUser.UserId, UpdateTime = DateTime.Now, Status = CommonHelper.To<int>(StatusType.Active), PlatformType = platformType.Value, }; EmeBLL.CreateNotice(addModel, LoginUserManager.CurrLoginUser.UserId); var rightBranchs = rightBranch.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (rightBranchs.Length > 0) { var addRight = AddNoticeRights(rightBranchs, addModel.Id); strMessage = (addRight? "添加成功!" : "操作失败!"); return Json(new { status = addRight, msg = strMessage }); } return Json(new { status = true, msg = strMessage }); } catch { return Json(new { state = false, msg = strMessage }, JsonRequestBehavior.DenyGet); } }
/// <summary> /// 作者:Vincen /// 时间:2014.04.30 /// 描述:更新公告通知(及权限) /// </summary> /// <param name="model"></param> /// <param name="rightBranchs"></param> /// <param name="loginUserId"></param> /// <returns></returns> public static bool UpdateNoticeRights(Notice model, string[] rightBranchs, int loginUserId) { using (var edb = new EmeEntities()) { try { var edidModel = edb.Notice.FirstOrDefault(p => p.Id == model.Id); if (edidModel != null) { edidModel.Subject = model.Subject; edidModel.NContent = model.NContent; edidModel.BeginDate = model.BeginDate; edidModel.EndDate = model.EndDate; edidModel.IsTop = model.IsTop; edidModel.UpdateBy = model.UpdateBy; edidModel.UpdateTime = model.UpdateTime; edidModel.Remark = model.Remark; if (model.IsTop == true) { edidModel.SetTopTime = DateTime.Now; } edb.Entry(edidModel).State = EntityState.Modified; //先把状态设置成无效 foreach (var item in edidModel.NoticeRights) { item.Status = ConvertEnum.StatusTypeForDelete; item.UpdateTime = DateTime.Now; edb.Entry(item).State = EntityState.Modified; } } //把选中的,添加或者设置状态为有效 foreach (var item in rightBranchs) { var branchId = CommonHelper.To<int>(item); if (!edb.NoticeRights.Any(p => p.Id == model.Id && p.BranchId == branchId)) { var nrmodel = new NoticeRights() { NoticeId = model.Id, BranchId = branchId, Status = ConvertEnum.StatusTypeForActive, CreateBy = model.UpdateBy, CreateTime = DateTime.Now }; edb.Entry(nrmodel).State = EntityState.Added; } else { var nrModel = edb.NoticeRights.SingleOrDefault(p => p.NoticeId == model.Id && p.BranchId == branchId); if (nrModel != null) { nrModel.UpdateBy = model.UpdateBy; nrModel.UpdateTime = DateTime.Now; nrModel.Status = CommonHelper.To<int>(ConvertEnum.StatusTypeForActive); edb.Entry(nrModel).State = EntityState.Modified; } } } var result = edb.SaveChanges() > 0; return result; } catch (Exception e) { // 异常日志消息队列 Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs() { ExceptionType = CommonHelper.To<int>(ExceptionType.Function), Message = string.Format("EmeBLL-UpdateNoticeRights:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink), IsTreat = false, CreateBy = loginUserId, CreateTime = DateTime.Now }); return false; } } }
/// <summary> /// 作者:Vincen /// 时间:2014.04.30 /// 描述:创建公告通知对象 /// </summary> /// <param name="model"></param> /// <param name="loginUserId"></param> /// <returns></returns> public static bool CreateNotice(Notice model, int loginUserId) { using (var edb = new EmeEntities()) { try { edb.Entry(model).State = EntityState.Added; var result = edb.SaveChanges() > 0; return result; } catch (Exception e) { Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs() { ExceptionType = CommonHelper.To<int>(ExceptionType.Message), Message = string.Format("EmeBLL-CreateNotice:{0};{1};{2}", e.Message, e.InnerException, e.HelpLink), IsTreat = false, CreateBy = loginUserId, CreateTime = DateTime.Now }); return false; } } }