public async Task <OutputResponse> Add(NotificationTemplateDTO notificationTemplate) { var isFound = await _context.NotificationTemplates.AnyAsync(x => x.TemplateName.ToLower() == notificationTemplate.TemplateName.ToLower()); if (isFound) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification template name already exist, duplicates not allowed" }); } var mappedNotificationTemplate = new AutoMapperHelper <NotificationTemplateDTO, NotificationTemplates>().MapToObject(notificationTemplate); mappedNotificationTemplate.RowAction = "I"; mappedNotificationTemplate.DateCreated = DateTime.UtcNow; await _context.NotificationTemplates.AddAsync(mappedNotificationTemplate); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.AddNewSuccess }); }
public NotificationTemplate(NotificationTemplateDTO source) { NotificationTemplateID = source.NotificationTemplateID; OrganizationID = source.OrganizationID; NotificationTypeID = source.NotificationTypeID; SubNotificationTypeID = source.SubNotificationTypeID; SubjectTemplate = source.SubjectTemplate; BodyTemplate = source.BodyTemplate; }
public async Task <IActionResult> Update([FromBody] NotificationTemplateDTO notificationTemplate) { var outputHandler = await _service.Update(notificationTemplate); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Ok(outputHandler.Message)); }
private async Task <NotificationTemplateDTO> GetNotificationTemplate(int templateId) { string url = $"{NotificationsApiUrl}NotificationTemplates/GetById?templateId={templateId}"; var NotificationTemplate = new NotificationTemplateDTO(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Get(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { NotificationTemplate = response.ContentAsType <NotificationTemplateDTO>(); } else { ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(NotificationTemplate); }
public async Task <IActionResult> Edit([Bind] NotificationTemplateDTO notificationTemplate) { string url = $"{NotificationsApiUrl}NotificationTemplates/Update"; var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Put(accessToken, url, notificationTemplate); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Notification template has been successfully updated", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to update notification template", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(View(notificationTemplate)); }
public async Task <OutputResponse> Update(NotificationTemplateDTO notificationTemplate) { var notificationTemplateToUpdate = await _context.NotificationTemplates.FirstOrDefaultAsync(x => x.TemplateId.Equals(notificationTemplate.TemplateId)); if (notificationTemplateToUpdate == null) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification template specified does not exist, update cancelled" }); } var isFound = await _context.NotificationTemplates.Where(x => x.TemplateId != notificationTemplate.TemplateId).AnyAsync(x => x.TemplateName.ToLower() == notificationTemplate.TemplateName.ToLower()); if (isFound) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification template name already exist, duplicates not allowed" }); } //update details notificationTemplateToUpdate.TemplateName = notificationTemplate.TemplateName; notificationTemplateToUpdate.Interval = notificationTemplate.Interval; notificationTemplateToUpdate.IntervalUnit = notificationTemplate.IntervalUnit; notificationTemplateToUpdate.RepeatCount = notificationTemplate.RepeatCount; notificationTemplateToUpdate.RowAction = "U"; notificationTemplateToUpdate.ModifiedBy = notificationTemplate.CreatedBy; notificationTemplateToUpdate.DateModified = DateTime.UtcNow; await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.UpdateSuccess }); }
public async Task <IActionResult> VerifyDelete(int templateId) { string url = $"{NotificationsApiUrl}NotificationTemplates/Delete?templateId={templateId}"; var NotificationTemplate = new NotificationTemplateDTO(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Delete(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Notification template has been successfully deleted", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to delete notification template", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(View(await GetNotificationTemplate(templateId))); }