public NotificationDetailsPage(Model.Notification notification) { InitializeComponent(); NavigationPage.SetHasBackButton(this, true); BindingContext = model = new NotificationDetailsViewModel { _notification = notification }; }
public async Task <ActionResult> SaveNotification(NotificationDetailsViewModel model) { //ModelState.AddModelError("EmailSubject", "Test Error."); if (ModelState.IsValid) { model.Title = BuildNotificationTitle(model); if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.Draft) { model.Status = NotificationStatus.Draft; } else if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.SendNow) { model.Status = NotificationStatus.Scheduled; model.TimeZoneId = TimeZoneHelper.DefaultTimeZoneId; // TO DO: Get the time zone from the user context. model.ScheduledDT = TimeZoneHelper.Now(model.TimeZoneId); } else { model.Status = NotificationStatus.Scheduled; } var userGroupIds = new List <string>(); userGroupIds.AddRange(model.NotificationGroupIds); userGroupIds.AddRange(model.ConnectionGroupIds); if (string.IsNullOrEmpty(model.Id)) { model.Id = Guid.NewGuid().ToString("N"); model.CreatedUTC = DateTime.UtcNow; model.CreatedBy = User.GetUserId(); var insertNote = model.ProjectTo <Angelo.Connect.Models.Notification>(); await _notificationManager.InsertNotificationAsync(insertNote, userGroupIds); } else { var updateNote = model.ProjectTo <Angelo.Connect.Models.Notification>(); await _notificationManager.UpdateNotificationAsync(updateNote, userGroupIds); } if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.SendNow) { await _jobs.EnqueueAsync <NotificationProcessor>(proc => proc.ExecuteNotification(model.Id)); model.Status = NotificationStatus.Processing; } return(Ok(model)); } return(BadRequest(ModelState)); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IViewComponentResult> InvokeAsync(string id, string ownerLevel, string ownerId) { if (string.IsNullOrEmpty(ownerLevel)) { return(new ViewComponentPlaceholder()); } NotificationDetailsViewModel model; if (string.IsNullOrEmpty(id)) { // Create new notification model = new NotificationDetailsViewModel() { OwnerLevel = (OwnerLevel)Enum.Parse(typeof(OwnerLevel), ownerLevel), OwnerId = ownerId, Status = NotificationStatus.Draft, ScheduleAction = NotificationDetailsViewModel.ScheduleActions.Draft, SendEmail = true, TimeZoneId = TimeZoneHelper.DefaultTimeZoneId // TO DO: Get the default time zone from the user context. }; model.ScheduledDT = TimeZoneHelper.Now(model.TimeZoneId); } else { // Load existing notification var note = await _notificationManager.GetNotificationAsync(id); if (note == null) { return(new ViewComponentPlaceholder()); } model = note.ProjectTo <NotificationDetailsViewModel>(); model.ScheduleAction = NotificationDetailsViewModel.ScheduleActions.Draft; if (string.IsNullOrEmpty(model.TimeZoneId)) { model.TimeZoneId = TimeZoneHelper.DefaultTimeZoneId; // TO DO: Get the default time zone from the user context. model.ScheduledDT = TimeZoneHelper.Now(model.TimeZoneId); } await LoadUserGroupsAsync(model, id); } ViewData["EmailHeaderSelectListItems"] = GetEmailHeaderSelectListItems(model.EmailHeaderId); ViewData["ownerLevel"] = ownerLevel ?? string.Empty; ViewData["ownerId"] = ownerId ?? string.Empty; ViewData["TimeZoneList"] = TimeZoneHelper.GetTimeZoneSelectList(); return(await Task.Run(() => { return View(model); })); }
protected string BuildNotificationTitle(NotificationDetailsViewModel model) { if (!string.IsNullOrEmpty(model.EmailSubject)) { return((model.EmailSubject.Length > 30) ? model.EmailSubject.Substring(0, 30) : model.EmailSubject); } else if (!String.IsNullOrEmpty(model.SmsMessage)) { return((model.SmsMessage.Length > 30) ? model.SmsMessage.Substring(0, 30) : model.SmsMessage); } else { return(model.Id); } }
private async Task LoadUserGroupsAsync(NotificationDetailsViewModel model, string id) { var userGroups = await _notificationManager.GetUserGroupsAssignedToNotificationAsync(id); foreach (var ug in userGroups) { if (ug.UserGroupType == UserGroupType.ConnectionGroup) { model.ConnectionGroups.Add(ug); } else { model.NotificationGroups.Add(ug); } } }