Ejemplo n.º 1
0
 public HttpResponseMessage UpdateInstAnnouncement(AddAnnouncementDTO announceDTO)
 {
     try
     {
         var user = UserHelper.GetCurrentUser();
         return(ResponseWrapper.SuccessResponse(repository.UpdateAnnouncement(announceDTO, a => a.Type == "I" && a.InstituteId == user.InstId)));
     }
     catch (Exception e)
     {
         return(ResponseWrapper.ExceptionResponse(e));
     }
 }
Ejemplo n.º 2
0
        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)
            }));
        }
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                AnnouncementModel announcementModel = new AnnouncementModel();

                UpdateModel(announcementModel);

                announcementRepository.UpdateAnnouncement(announcementModel);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("Edit"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Update(AnnouncementInfo announcementInfo)
        {
            try
            {
                announcementInfo.ModifiedByAccountId = CurrentUser.AccountId;
                announcementInfo.ModifiedOn          = DateTime.Now;

                using (AnnouncementRepository Repo = new AnnouncementRepository())
                {
                    Repo.UpdateAnnouncement(announcementInfo);
                }

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Announcement updated successfully.");

                return(RedirectToAction("Manage", "Announcement"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Announcement", "Update")));
            }
        }
        public IHttpActionResult EditAnnouncement(int id, [FromBody] AnnouncementFormData data)
        {
            if (!user_service.IsAuthorizedToEditAnnouncements(id))
            {
                return(Unauthorized());
            }

            // for preflight requests
            if (RequestUtility.IsPreFlightRequest(Request))
            {
                return(Ok());
            }

            var result = data.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }

            announcement_repository.UpdateAnnouncement(id, data);
            return(Ok());
        }
Ejemplo n.º 6
0
        public async Task CanUpdateAnnouncement()
        {
            var announcement = new Announcement()
            {
                PatrolId             = 1,
                AnnouncementMarkdown = "Hello world",
                CreatedAt            = DateTime.Now,
                CreatedByUserId      = 1,
                PostAt     = DateTime.Now,
                Subject    = "Test",
                IsInternal = true,
                IsPublic   = true
            };

            await _announcementRepository.InsertAnnouncement(announcement);

            announcement.AnnouncementMarkdown = "Test";

            await _announcementRepository.UpdateAnnouncement(announcement);

            var announcements = await _announcementRepository.GetAnnouncements(1, null, true, true);

            Assert.AreEqual(announcement.AnnouncementMarkdown, announcements.ToList()[0].AnnouncementMarkdown);
        }