public void UpdateAnnouncement(Announcement announcement, int userInfoId) { var user = GameSchoolEntities.UserInfoes.Where(u => u.UserInfoId == userInfoId).SingleOrDefault(); if (user == null) throw new GameSchoolException(string.Format("User does not exist. UserInfoId = {0}", userInfoId)); announcement.UpdateDateTime = DateTime.Now; announcement.UpdatedBy = user.Username; Save(); }
public ActionResult CreateAnnouncement(Announcement model, int? id) { var user = MembershipHelper.GetUser(); if (ModelState.IsValid) { AnnouncementService.CreateAnnouncement(model, user.UserInfoId); return RedirectToAction("Announcement", "Course", new {id = model.AnnouncementId}); } if (id.HasValue) { ViewBag.CourseId = id.Value; ViewBag.CourseList = new SelectList(CourseService.GetCoursesByUserInfoId(user.UserInfoId), "CourseId", "Name"); ViewBag.LevelList = new SelectList(LevelService.GetLevels(id.Value), "LevelId", "Name"); } return View(model); }
public ActionResult EditAnnouncement(Announcement model, int? id) { if (id.HasValue) { var user = MembershipHelper.GetUser(); if (ModelState.IsValid) { var announcement = AnnouncementService.GetAnnouncementByAnnouncementId(id.Value); if (TryUpdateModel(announcement)) { AnnouncementService.UpdateAnnouncement(announcement, user.UserInfoId); return RedirectToAction("Announcement", "Course", new { id = announcement.AnnouncementId }); } } ViewBag.CourseId = model.CourseId; ViewBag.CourseList = new SelectList(CourseService.GetCoursesByUserInfoId(user.UserInfoId), "CourseId", "Name"); ViewBag.LevelList = new SelectList(LevelService.GetLevels(model.CourseId), "LevelId", "Name"); return View(model); } return RedirectToAction("Notfound", "Home"); }
public ActionResult CreateAnnouncement(int? id) { var model = new Announcement(); if (id.HasValue) { var user = MembershipHelper.GetUser(); ViewBag.CourseId = id.Value; model.CourseId = id.Value; model.DisplayDateTime = DateTime.Now; ViewBag.CourseList = new SelectList(CourseService.GetCoursesByUserInfoId(user.UserInfoId), "CourseId", "Name"); ViewBag.LevelList = new SelectList(LevelService.GetLevels(id.Value), "LevelId", "Name"); } return View(model); }