public async Task <IActionResult> ViewSched(UserTaskSchedule userTaskSchedule = null) { var dict = GetCookies(); var utsList = new List <UserTaskSchedule>(); //Get Task Schedules var taskSchedules = await GetTaskSched(dict); //Get Usertasks var userTasks = await GetUserTasks(dict); //Populate list foreach (var ts in taskSchedules) { var ut = userTasks.Find(u => u.Id == ts.UserTaskId); utsList.Add(new UserTaskSchedule() { TaskSchedule = ts, UserTaskList = new UserTaskList() { UserTask = ut } }); } //TODO Show all currently scheduled tasks, maybe have next scheduled date listed too and skip/send now return(View(utsList)); }
public async Task <IActionResult> EditSched(string id) { var dict = GetCookies(); var uts = await _data.GetOrSetCachedData(dict, Enums.DataType.TaskSchedule, id); //could do empty check, but this is editing one, so we know it exists var taskSchedule = uts.FirstOrDefault().ToObject <TaskSchedule>(); var ut = await GetUserTasks(dict, taskSchedule.UserTaskId); var usrtask = ut.FirstOrDefault(); var userTaskSchedule = new UserTaskSchedule() { TaskSchedule = taskSchedule, UserTaskList = new UserTaskList() { UserTask = usrtask } }; string[] days = Enum.GetNames(typeof(DayOfWeek)); ViewData["ContactPreference"] = ContactEnumToList(usrtask.ContactMethod.ToString()); ViewData["Frequency"] = FrequencyEnumToList(taskSchedule.Frequency.ToString()); ViewData["DayFrequency"] = DayFrequencyEnumToList(taskSchedule.DayFrequency.ToString()); ViewData["Days"] = GetDays(taskSchedule.DayOfMonth.ToString()); ViewData["DayOfWeek"] = DayOfWeekToList(days); return(View(userTaskSchedule)); }
public async Task <IActionResult> SchedTask(UserTaskSchedule userTaskSchedule) { var dict = GetCookies(); var ut = userTaskSchedule.UserTaskList.UserTask; var ts = userTaskSchedule.TaskSchedule; ut.AssignedDateTime = DateTime.Now; ut.Id = Guid.NewGuid().ToString(); ut.UidToken = dict["uid"]; ut.Complete = false; ts.Time = ut.SendTime; var jData = JsonConvert.SerializeObject(ut); //add the usertask await _data.UpdateAndClearCache(dict, Enums.DataType.UserTasks, Enums.UpdateType.Add, jData); ts.Id = Guid.NewGuid().ToString(); ts.UserTaskId = ut.Id; var messageId = await ScheduleNotification(ut, dict, ts); //TODO update usertask message id this is the recurring job, not the individual one ut.MessageId = messageId; var j2Data = JsonConvert.SerializeObject(ut); await _data.UpdateAndClearCache(dict, Enums.DataType.UserTasks, Enums.UpdateType.Edit, j2Data); //add the task schedule jData = JsonConvert.SerializeObject(ts); await _data.UpdateAndClearCache(dict, Enums.DataType.TaskSchedule, Enums.UpdateType.Add, jData); return(RedirectToAction("ViewSched")); }
public async Task <IActionResult> EditSched(UserTaskSchedule userTaskSchedule) { var dict = GetCookies(); var jData = JsonConvert.SerializeObject(userTaskSchedule.TaskSchedule); //I think we need to delete it then add a new one await _data.UpdateAndClearCache(dict, Enums.DataType.TaskSchedule, Enums.UpdateType.Edit, jData); //schedule new one return(RedirectToAction("ViewSched")); }