public ActionResult EditAnnouncement(AnnouncementEditModel model, string type, string home, string userspace) { if (home == null && userspace == null) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请至少选择一个显示区域"); TempData["model"] = model; return RedirectToAction("EditAnnouncement"); } model.DisplayArea = string.Format("{0},{1}", home, userspace); if (type == "disenabled") { model.EnabledDescription = false; model.IsHyperLink = false; } if (type == "text") { model.EnabledDescription = true; model.IsHyperLink = false; } if (type == "hyperlink") { model.EnabledDescription = true; model.IsHyperLink = true; } if (model.ReleaseDate == DateTime.MinValue || model.ExpiredDate == DateTime.MinValue) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请正确填写日期"); TempData["model"] = model; return RedirectToAction("EditAnnouncement"); } if (model.ReleaseDate > model.ExpiredDate) { DateTime changDate = model.ReleaseDate; model.ReleaseDate = model.ExpiredDate; model.ExpiredDate = changDate; } model.UserId = UserContext.CurrentUser.UserId; if (model.Id == 0 || model.Id == null) { announcementService.Create(model.AsAnnouncement()); } else { announcementService.Update(model.AsAnnouncement()); } return RedirectToAction("ManageAnnouncements"); }
public ActionResult EditAnnouncement(long? id = null) { pageResourceManager.InsertTitlePart("创建公告"); AnnouncementEditModel model = null; if (!id.HasValue) { model = new AnnouncementEditModel(); var tempdata = TempData.Get<AnnouncementEditModel>("model", null); if (tempdata != null) model = tempdata; } else { var announcement = announcementService.Get(id.Value); model = announcement.AsEditModel(); } return View(model); }