public ResponseStatus AddNotice(HttpRequestBase req) { //return service.Add(req, // () => new Notice(), // ()=> new NoticeDAL(), // (notice) => // { // notice.Content = req.Form["content"].ToString(); // notice.PublishTime = Convert.ToDateTime(req.Form["publish"]); // notice.NType = Convert.ToByte(req.Form["ntype"]) == 1 ? NoticeType.All_MEMBER : NoticeType.ASSOCIATION; // notice.isTop = Convert.ToByte(req.Form["isTop"]); // }); noticeDal = new NoticeDAL(); Notice notice = new Notice() { Content = req.Form["content"].ToString(), PublishTime = Convert.ToDateTime(req.Form["publish"]), NType = Convert.ToByte(req.Form["ntype"]) == 1 ? NoticeType.All_MEMBER : NoticeType.ASSOCIATION, isTop = Convert.ToByte(req.Form["isTop"]), }; if (notice.isTop == 1) { int topCount = 0; ResponseStatus resp = noticeDal.GetTopCount(ref topCount,NoticeType.NONE,false); if (resp != ResponseStatus.SUCCESS) { return resp; } else { if (topCount >= GLB.noticeTopCount) { notice.isTop = 0; notice.isPreTop = 1; } } } bool isSuccess = noticeDal.Insert(notice); noticeDal.ReturnUnitToPool(); return isSuccess ? ResponseStatus.SUCCESS : ResponseStatus.FAILED; }
public ActionResult Update(int id,int curPage) { if (Request.Form != null && Request.Form.Count > 0) { resp = noticeService.UpdateNotice(Request); return this.JudgeResult(resp, () => RedirectToAction("Details", new { ntype = Convert.ToByte(Request.Form["ntype"]) == 1 ? NoticeType.All_MEMBER : NoticeType.ASSOCIATION, curpage = curPage, msg = string.Format("修改了公告:{0}", Request.Form["content"]) })); } else { Notice notice = null; resp = noticeService.GetNotice(id, ()=>notice = new Notice()); return this.JudgeResult(resp, () => { conta_Notice = new Container_Notice(); conta_Notice.notice = notice; conta_Notice.CurPage = curPage; return View(conta_Notice); }); } }
public ResponseStatus UpdateNotice(HttpRequestBase req) { //return service.Update(req, // () => new Notice(), // () => new NoticeDAL(), // (notice) => // { // notice.ID = Convert.ToInt32(req.Form["id"]); // notice.Content = req.Form["content"].ToString(); // notice.PublishTime = Convert.ToDateTime(req.Form["publish"]); // notice.NType = Convert.ToByte(req.Form["ntype"]) == 1 ? NoticeType.All_MEMBER : NoticeType.ASSOCIATION; // notice.isTop = Convert.ToByte(req.Form["isTop"]); // }); ResponseStatus resp = ResponseStatus.NONE; noticeDal = new NoticeDAL(); Notice notice = new Notice() { ID = Convert.ToInt32(req.Form["id"]), Content = req.Form["content"].ToString(), PublishTime = Convert.ToDateTime(req.Form["publish"]), NType = Convert.ToByte(req.Form["ntype"]) == 1 ? NoticeType.All_MEMBER : NoticeType.ASSOCIATION, isTop = Convert.ToByte(req.Form["isTop"]) }; resp = noticeDal.Update(notice) ? ResponseStatus.SUCCESS : ResponseStatus.FAILED; if (resp == ResponseStatus.SUCCESS) { if (notice.isTop == 0) { int topCount = 0; resp = noticeDal.GetTopCount(ref topCount, NoticeType.NONE, false); if (resp != ResponseStatus.SUCCESS) { } else { Notice noticeForTop; if (topCount < GLB.noticeTopCount) { noticeForTop = new Notice(); resp = noticeDal.GetSingleTop(noticeForTop); if (resp == ResponseStatus.SUCCESS) { noticeForTop.isTop = 1; noticeForTop.isPreTop = 0; resp = noticeDal.Update(noticeForTop) ? ResponseStatus.SUCCESS : ResponseStatus.FAILED; } else if (resp == ResponseStatus.NOT_DATA) resp = ResponseStatus.SUCCESS; } } } } noticeDal.ReturnUnitToPool(); return resp; }