// // GET: /Announcement/ public ActionResult Index() { var announcementRepository = new AnnouncementRepository(); var activeAnnouncements = announcementRepository.GetActiveAnnouncements().ToList(); return(View(activeAnnouncements)); }
// GET: Admin/Announcement/Update public ActionResult Update(string id = "") { try { int _id; AnnouncementInfo _announcement = null; if (!int.TryParse(id, out _id)) { return(RedirectToAction("Manage", "Announcement")); } using (AnnouncementRepository Repo = new AnnouncementRepository()) { _announcement = Repo.GetAnnouncementById(_id); } if (_announcement == null) { return(RedirectToAction("Manage", "Announcement")); } return(View(_announcement)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Update"))); } }
public async Task <IActionResult> Announcements(bool activeOnly = true) { var user = await userManager.GetUserAsync(User); AnnouncementRepository repo = new AnnouncementRepository(configModel.ConnectionString); List <AnnouncementModel> announcements; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { activeOnly = true; } try { announcements = repo.GetAnnouncementList(activeOnly); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "", Announcements = announcements })); }
public ActionResult ComposeAnnouncement(AnnouncementModel model) { AnnouncementRepository repository = new AnnouncementRepository(); repository.AddAnnouncement(User.Identity.Name, model.title, model.body); return(RedirectToAction("SendAnnouncement")); }
/// <summary> /// 获取所有通知公告 /// </summary> /// <returns></returns> public async Task <List <AnnouncementDTO> > GetAllAnnouncementAsync() { return(await Task.Run(() => { var announcements = AnnouncementRepository.GetModels(a => a.id != 0); return Mapper.Map <List <AnnouncementDTO> >(announcements.ToList()); })); }
/// <summary> /// 获取正在推送的通知公告 /// </summary> /// <returns></returns> public async Task <List <AnnouncementDTO> > GetPushAnnouncementAsync() { return(await Task.Run(() => { var announcements = AnnouncementRepository.GetModels(a => a.endPushDate > DateTime.Now && a.isShow); return Mapper.Map <List <AnnouncementDTO> >(announcements.ToList()); })); }
public async Task <IActionResult> AnnouncementCreation(AnnouncementModel announcement) // TODO: put in parameter list { var user = await userManager.GetUserAsync(User); AnnouncementRepository ancRepo = new AnnouncementRepository(configModel.ConnectionString); VolunteerRepository volunteerRepo = new VolunteerRepository(configModel.ConnectionString); VolunteerModel volunteer; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Get the current user's volunteer profile so we can get their name volunteer = volunteerRepo.GetVolunteer(user.VolunteerId); // Validate the inputs // Note that in C#, DateTimes are never null, so instead of checking for null, we check for DateTime.MinValue, which is the // default value that ASP.NET's model binding will provide if the date is not included in the API call. if (String.IsNullOrEmpty(announcement.Title)) { return(Utilities.ErrorJson("Title field cannot be empty")); } if (announcement.StartDate == DateTime.MinValue || announcement.EndDate == DateTime.MinValue) { return(Utilities.ErrorJson("Start and end date must be provided")); } if (announcement.StartDate > announcement.EndDate) { return(Utilities.ErrorJson("Start date must be no later than end date")); } try { ancRepo.CreateAnnouncement(new AnnouncementModel { Title = announcement.Title, Message = announcement.Message, Author = volunteer.FirstName + " " + volunteer.LastName, LastUpdateBy = volunteer.FirstName + " " + volunteer.LastName, StartDate = announcement.StartDate, EndDate = announcement.EndDate }); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "" })); }
public object Archive(int?page) { var announcementRepository = new AnnouncementRepository(); var archivedAnnouncements = announcementRepository.GetArchivedAnnouncements(); var pageNumber = page ?? 0; // if no page was specified in the querystring, default to the first page (1) var onePageOfAnnouncements = archivedAnnouncements.ToPagedList(pageNumber, 10); // will only contain 25 products max because of the pageSize ViewBag.OnePageOfAnnouncements = onePageOfAnnouncements; return(View("Archive")); }
/// <summary> /// 分页获取通知公告 /// </summary> /// <param name="pageIndex">页数</param> /// <param name="pageSize">页码</param> /// <returns></returns> public async Task <PageDTO <AnnouncementDTO> > GetAnnouncementAsyncByPage(int pageIndex, int pageSize) { return(await Task.Run(() => { var announcements = AnnouncementRepository.GetModelsByPage(pageSize, pageIndex, true, a => a.createDate, a => a.endPushDate < DateTime.Now, out var total); var list = Mapper.Map <List <AnnouncementDTO> >(announcements.ToList()); return new PageDTO <AnnouncementDTO>(pageIndex, pageSize, total, list); })); }
public async Task <IActionResult> AnnouncementEdit(AnnouncementModel announcement) { var user = await userManager.GetUserAsync(User); AnnouncementRepository repo = new AnnouncementRepository(configModel.ConnectionString); AnnouncementModel dbAnc; VolunteerRepository volunteerRepo = new VolunteerRepository(configModel.ConnectionString); VolunteerModel volunteer; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } if (String.IsNullOrEmpty(announcement.Title)) { return(Utilities.ErrorJson("Title field cannot be empty")); } if (announcement.StartDate == DateTime.MinValue || announcement.EndDate == DateTime.MinValue) { return(Utilities.ErrorJson("Start and end date must be provided")); } if (announcement.StartDate > announcement.EndDate) { return(Utilities.ErrorJson("Start date must be no later than end date")); } dbAnc = repo.GetAnnouncement(announcement.Id); if (dbAnc == null) { return(Utilities.ErrorJson("Not a valid announcement")); } volunteer = volunteerRepo.GetVolunteer(user.VolunteerId); announcement.LastUpdateBy = volunteer.FirstName + " " + volunteer.LastName; try { repo.UpdateAnnouncement(announcement); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(new JsonResult(new { Error = "", Announcement = repo.GetAnnouncement(announcement.Id) })); }
/// <summary> /// 获取指定的置顶通知公告 /// </summary> /// <param name="count"></param> /// <returns></returns> public async Task <List <AnnouncementDTO> > GetAnnouncementsOnTopAsync(int count) { return(await Task.Run(() => { var announcements = AnnouncementRepository.GetModels(a => a.isTop && a.endPushDate < DateTime.Now && a.isShow ); return Mapper.Map <List <AnnouncementDTO> >(announcements.Take(count).ToList()); })); }
public static ContentService CreateContentService() { IUnitOfWork uow = new EFUnitOfWork(); IArticleRepository articleRepository = new ArticleRepository(uow); ISiteNodeRepository siteNodeRepository = new SiteNodeRepository(uow); INewsRepository newsRepository = new NewsRepository(uow); ICompanyRepository companyRepository = new CompanyRepository(uow); IIdeaRepository ideaRepository = new IdeaRepository(uow); ICommentRepository commentRepository = new CommentRepository(uow); IVacancyRepository vacancyRepository = new VacancyRepository(uow); IAnnouncementRepository announcementRepository = new AnnouncementRepository(uow); return(new ContentService(articleRepository, siteNodeRepository, newsRepository, companyRepository, ideaRepository, commentRepository, vacancyRepository, announcementRepository, uow, HttpContext.Current)); }
private async void LoadPersonalAnnouncements() { try { Announcements = await AnnouncementRepository.GetAllAsync(); } catch (Exception e) { MessageDialog messageDialog = new MessageDialog($"Couldn't establish a connection to the database. \n{e.Message}"); messageDialog.Commands.Add(new UICommand("Try again", new UICommandInvokedHandler(this.CommandInvokedHandler))); messageDialog.Commands.Add(new UICommand("Close")); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; await messageDialog.ShowAsync(); } }
public ActionResult Amend(int id) { var announcementRepository = new AnnouncementRepository(); Announcement announcement; if (id > 0) { announcement = announcementRepository.GetAnnouncementById(id); } else { announcement = new Announcement() { ExpiryDate = System.DateTime.Today }; } return(PartialView("Amend", announcement)); }
// GET: Admin/Announcement/Manage public ActionResult Manage() { try { var _announcementList = new List <AnnouncementInfo>(); using (AnnouncementRepository Repo = new AnnouncementRepository()) { _announcementList = Repo.GetAnnouncementList(); } return(View(_announcementList)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Manage"))); } }
public ViewResult Index() { EventRepository eventRepository = new EventRepository(); PhotoRepository photoRepository = new PhotoRepository(); AnnouncementRepository announcementRepository = new AnnouncementRepository(); var homeModel = new HomeModel() { LatestAnnouncements = announcementRepository.GetLatestAnnouncements(4).ToList(), ActiveAnnouncementsCount = announcementRepository.GetActiveAnnouncements().Count(), LatestEvents = eventRepository.GetLatestEvents(6).ToList(), LatestNews = eventRepository.GetLatestNews(3).ToList(), latestPhotos = photoRepository.GetCategoryImages(38) }; // ViewBag.FullUrl = Util.GetApplicationFullUrlWithoutLastSlash(); return(View(homeModel)); }
public ActionResult GetEmployeeMenu() { var _menu = new MenuViewModel(); AnnouncementInfo _announcement = null; AlbumInfo _album = null; using (AnnouncementRepository Repo = new AnnouncementRepository()) { _announcement = Repo.GetRecentAnnouncement(); } using (AlbumRepository Repo = new AlbumRepository()) { _album = Repo.GetRecentAlbum(); } if (_announcement != null) { TimeSpan tSpan = (DateTime.Parse(_announcement.CreatedOn.Value.ToString()).AddDays(1)).Subtract(DateTime.Now); double diff = tSpan.TotalDays; if (diff > 0) { _menu.IsNewAnnouncement = true; } } if (_album != null) { TimeSpan tSpan = (DateTime.Parse(_album.CreatedOn.Value.ToString()).AddDays(1)).Subtract(DateTime.Now); double diff = tSpan.TotalDays; if (diff > 0) { _menu.IsNewAlbum = true; } } return(PartialView("_EmployeeMenu", _menu)); }
public async void PostAnnouncement(Passenger passenger) { try { if (!await AnnouncementRepository.PostAnnouncement(Title, Content, passenger)) { MessageDialog messageDialog = new MessageDialog("Invalid announcement. \nPlease try again."); messageDialog.Commands.Add(new UICommand("Close")); messageDialog.CancelCommandIndex = 0; await messageDialog.ShowAsync(); } LoadAnnouncements(); } catch (Exception e) { MessageDialog messageDialog = new MessageDialog($"Couldn't establish a connection to the database. \n{e.Message}"); messageDialog.Commands.Add(new UICommand("Close")); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; await messageDialog.ShowAsync(); } }
public ActionResult Create(AnnouncementInfo announcementInfo) { try { announcementInfo.CreatedByAccountId = CurrentUser.AccountId; announcementInfo.CreatedOn = DateTime.Now; using (AnnouncementRepository Repo = new AnnouncementRepository()) { Repo.SaveAnnouncement(announcementInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Announcement created successfully."); return(RedirectToAction("Manage", "Announcement")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Create"))); } }
public ActionResult Save(Announcement announcement) { try { var announcementRepository = new AnnouncementRepository(); // announcement.userName = HttpContext.User.Identity.Name; if (HttpContext.Session != null) { announcement.UserId = HttpContext.Session["UserId"] as int?; } announcement.CreateDate = DateTime.Now.Date; announcement.LastModified = DateTime.Now.Date; announcementRepository.Save(announcement); return(RedirectToAction("Index")); } catch (Exception ex) { throw (ex); } }
public ActionResult Delete(string id = "") { try { int _id; AnnouncementInfo _announcement = null; if (!int.TryParse(id, out _id)) { return(RedirectToAction("Manage", "Announcement")); } using (AnnouncementRepository Repo = new AnnouncementRepository()) { _announcement = Repo.GetAnnouncementById(_id); } if (_announcement == null) { return(RedirectToAction("Manage", "Announcement")); } using (AnnouncementRepository Repo = new AnnouncementRepository()) { Repo.DeleteAnnouncement(_id); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Announcement deleted successfully."); return(RedirectToAction("Manage", "Announcement")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Delete"))); } }
public void SetUp() { _announcementRepository = new AnnouncementRepository(_connection); }
public void Initialize() { testDbConnectionString = ConfigurationManager.ConnectionStrings["ProgrammingClubM.Tests.Properties.Settings.clubmembershiptestsConnectionString"].ConnectionString; clubmembershipDataContext = new Models.DBObjects.ClubMembershipModelsDataContext(testDbConnectionString); announcementResource = new AnnouncementRepository(clubmembershipDataContext); }
public AnnouncementBusiness(IServiceProvider provider, AnnouncementRepository repository) : base(provider, repository) { this._repository = repository; }
public AnnouncementController(UserManager <User> userManager, IAnnouncementRepository <UserRegisterRequest, AnnouncementFilter> repository) { _repository = (AnnouncementRepository)repository; _userManager = userManager; }
public AnnouncementsController(AnnouncementRepository repo) : base() { announcement_repository = repo; user_service = new UserService(); }
public ActionResult DeleteLecturer(int lecturerId) { /* * Deleting a lecturer is quite an impactful action to the system's data because a lecturer record * has its primary key (student_id) as a foriegn key in other entities, thus prompting the associated * records in those entities to also be deleted. * * The worst case scenario for this, is when the deletion of a lecturer affects n number of entities (prompting their records to be removed also), where n is the maximum number of entities that * can be affected. * * This scenario occurs when the FYP time-period has commenced and the lecturer, being in supervision * of FYP group(s) and also, happened to propose "lecturer-intiated" projects and made announcements * (also attaching file resources to at least one of the announcement(s)) before (the commenement of * the FYP time-period), has decided to leave SP. In this worst case scenario, n turns out to be 4 * (The four affected entities are namely; Announcement, File_Resource, Group, * Industry_Lecturer_Project). * * Superificially, it might seem OK to have those record(s) in (all) the associated tables, deleted. * However practically, it would make no sense, to have a group (with students in it deleted) merely * because its supervisor has left SP. * * Hence, in practicality n would be modified as; n = 4 - 1 = 3, where the entity, "exempted" from * deletion is; Group. * * Additionally, it should be noted that n can be further reduced to; n = 3 - 2 = 1, where the * additional two entities, which should also be exempted deletion (alike the above-mentioned * Group entity) are; Announcement and File_Resource. However due to technical database * constraint, those two entities would not be removed from deletion. Thus, n is still; 3. * * Also, like Group, the records in the Industry_Lecturer_Project entity should not be deleted. Thus * n = 3 - 1 = 2; * * Hence as dicussed above, in the worst case scenario, only at most n entities can be affected, where * n is revealed to be 2. The affected entities are thus Announcement and File_Resource. * * Thus, with the above discussion, the code below deletes associated records from the the Announcement * and File_Resource entity. */ // Variable declaration and initialization. int numberOfRowsAffected = 0; IAnnouncementRepository announcementRepository = new AnnouncementRepository(); IFileResourceRepository fileResourceRepository = new FileResourceRepository(); IProjectRepository projectRepository = new ProjectRepository(); IGroupRepository groupRepository = new GroupRepository(); IEnumerable <Announcement> associatedAnnouncements = null; IEnumerable <object> associatedGroups = null; IEnumerable <dynamic> associatedIndustryLecturerProjects = null; try { associatedAnnouncements = announcementRepository.GetAnnouncementsByLecturerId(lecturerId); // Deleting records from the File_Resource entity. foreach (Announcement announcement in associatedAnnouncements) { fileResourceRepository.DeleteFileResourcesForAnnouncement(announcement.announcement_id); } // Deleting Announcement's records. announcementRepository.DeleteAnnouncementsForLecturer(lecturerId); associatedGroups = groupRepository.GetGroupsByLecturerId(lecturerId); // Disassociating any group records which are currently associated to the (to be) deleted lecturer record, by setting the group_role field in the Group entity to NULL. foreach (object group in associatedGroups) { int groupId = int.Parse(group.GetType().GetProperty("groupId").GetValue(group, null).ToString()); groupRepository.AssignSupervisor(null, groupId); } associatedIndustryLecturerProjects = projectRepository.GetIndustryLecturerProjectsByLecturerId(lecturerId); // Disassociating any project records which are currently associated to the (to be) deleted lecturer record, by setting the lecturer_id field in the Lecturer entity to NULL. foreach (dynamic project in associatedIndustryLecturerProjects) { projectRepository.SetLecturerId(project.project_id, null); } // Finally, once all records are properly settled, as from above, delete the lecturer (from the Lecturer entity). numberOfRowsAffected = lecturerRepository.DeleteLecturer(lecturerId); return(Json(new { rowsAffected = numberOfRowsAffected })); } catch (Exception e) { return(Json(new { rowsAffected = numberOfRowsAffected, error = e.Message })); } }