public async Task <OutputResponse> Add(ScheduledNotificationDTO scheduledNotification) { var patients = await _context.Patients.Select(x => x.PhoneNumber).ToArrayAsync() as string[]; if (patients is null) { return(new OutputResponse { IsErrorOccured = true, Message = "An error occured while adding recipients" }); } var mappedScheduledNotification = new AutoMapperHelper <ScheduledNotificationDTO, ScheduledNotifications>().MapToObject(scheduledNotification); mappedScheduledNotification.RowAction = "I"; mappedScheduledNotification.Recipients = patients; mappedScheduledNotification.DateCreated = DateTime.UtcNow; await _context.ScheduledNotifications.AddAsync(mappedScheduledNotification); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.AddNewSuccess }); }
public async Task <IActionResult> Edit([Bind] ScheduledNotificationViewModel scheduledNotificationViewModel) { ScheduledNotificationDTO scheduledNotification = scheduledNotificationViewModel.ScheduledNotification; string url = $"{NotificationsApiUrl}ScheduledNotifications/Update"; var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Put(accessToken, url, scheduledNotification); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Scheduled notification has been successfully updated", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to update scheduled notification", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } scheduledNotificationViewModel.EscalationRules = await GetEscalationRules(); scheduledNotificationViewModel.NotificationTemplates = await GetNotificationTemplates(); scheduledNotificationViewModel.NotificationChannels = await GetNotificationChannels(); return(View(scheduledNotificationViewModel)); }
public async Task <OutputResponse> Update(ScheduledNotificationDTO scheduledNotification) { var scheduledNotificationToUpdate = await _context.ScheduledNotifications.FirstOrDefaultAsync(x => x.NotificationId.Equals(scheduledNotification.NotificationId)); if (scheduledNotificationToUpdate == null) { return(new OutputResponse { IsErrorOccured = true, Message = "ScheduledNotification specified does not exist, update cancelled" }); } //update details scheduledNotificationToUpdate.ChannelId = scheduledNotification.ChannelId; scheduledNotificationToUpdate.Interval = scheduledNotification.Interval; scheduledNotificationToUpdate.IsActive = scheduledNotification.IsActive; scheduledNotificationToUpdate.Message = scheduledNotification.Message; scheduledNotificationToUpdate.Recipients = scheduledNotification.Recipients; scheduledNotificationToUpdate.TemplateId = scheduledNotification.TemplateId; scheduledNotificationToUpdate.RuleId = scheduledNotification.RuleId; scheduledNotificationToUpdate.StartDate = scheduledNotification.StartDate; scheduledNotificationToUpdate.RowAction = "U"; scheduledNotificationToUpdate.ModifiedBy = scheduledNotification.CreatedBy; scheduledNotificationToUpdate.DateModified = DateTime.UtcNow; await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.UpdateSuccess }); }
public async Task <IActionResult> Update([FromBody] ScheduledNotificationDTO scheduledNotification) { var outputHandler = await _service.Update(scheduledNotification); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Ok(outputHandler.Message)); }
public async Task <IActionResult> VerifyDelete(int notificationId) { string url = $"{NotificationsApiUrl}ScheduledNotifications/Delete?notificationId={notificationId}"; var ScheduledNotification = new ScheduledNotificationDTO(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Delete(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Scheduled notification has been successfully deleted", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to delete scheduled notification", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(View(await GetScheduledNotification(notificationId))); }