public HttpResponseMessage CreateStaffingSchedule(StaffingScheduleInput staffingScheduleInput)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    var task = new ScheduledTask();
                    task.UserId = UserId;

                    if (staffingScheduleInput.Typ == 1)
                    {
                        var      department = _departmentsService.GetDepartmentById(DepartmentId);
                        DateTime inputDate  = DateTime.Parse(staffingScheduleInput.Spd);

                        task.ScheduleType = (int)ScheduleTypes.SpecifcDateTime;

                        string[] timeParts = new List <string>().ToArray();
                        //if (staffingScheduleInput.Spt.Contains("AM") || staffingScheduleInput.Spt.Contains("PM"))
                        //{
                        timeParts = staffingScheduleInput.Spt.Split(char.Parse(":"));
                        //}
                        //else
                        //{
                        //	var timeFromInput = DateTime.ParseExact(staffingScheduleInput.Spt, "H:m", null, DateTimeStyles.None);
                        //	string time12Hour = timeFromInput.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));
                        //	timeParts = time12Hour.Split(char.Parse(":"));
                        //}

                        var dateOffset = new DateTimeOffset(inputDate.Year, inputDate.Month, inputDate.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), 0, TimeConverterHelper.GetOffsetForDepartment(department));

                        task.SpecifcDate = dateOffset.UtcDateTime;
                    }
                    else
                    {
                        task.ScheduleType = (int)ScheduleTypes.Weekly;

                        if (staffingScheduleInput.Spt.Contains("AM") || staffingScheduleInput.Spt.Contains("PM"))
                        {
                            task.Time = staffingScheduleInput.Spt;
                        }
                        else
                        {
                            var    timeFromInput = DateTime.ParseExact(staffingScheduleInput.Spt, "H:m", null, DateTimeStyles.None);
                            string time12Hour    = timeFromInput.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));

                            task.Time = time12Hour;
                        }
                    }

                    task.Sunday    = staffingScheduleInput.Sun;
                    task.Monday    = staffingScheduleInput.Mon;
                    task.Tuesday   = staffingScheduleInput.Tue;
                    task.Wednesday = staffingScheduleInput.Wed;
                    task.Thursday  = staffingScheduleInput.Thu;
                    task.Friday    = staffingScheduleInput.Fri;
                    task.Saturday  = staffingScheduleInput.Sat;
                    task.AddedOn   = DateTime.UtcNow;
                    task.Active    = true;
                    task.Data      = staffingScheduleInput.Ste;
                    task.TaskType  = (int)TaskTypes.UserStaffingLevel;
                    task.Note      = staffingScheduleInput.Not;

                    _scheduledTasksService.SaveScheduledTask(task);

                    return(Request.CreateResponse(HttpStatusCode.Created));
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    throw HttpStatusCode.InternalServerError.AsException();
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }
        public async Task <ActionResult> CreateStaffingSchedule(StaffingScheduleInput staffingScheduleInput, CancellationToken cancellationToken)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    var task = new ScheduledTask();
                    task.UserId = UserId;

                    if (staffingScheduleInput.Typ == 1)
                    {
                        var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

                        DateTime inputDate = DateTime.Parse(staffingScheduleInput.Spd);

                        task.ScheduleType = (int)ScheduleTypes.SpecifcDateTime;

                        string[] timeParts = new List <string>().ToArray();
                        timeParts = staffingScheduleInput.Spt.Split(char.Parse(":"));

                        var dateOffset = new DateTimeOffset(inputDate.Year, inputDate.Month, inputDate.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), 0, TimeConverterHelper.GetOffsetForDepartment(department));

                        task.SpecifcDate = dateOffset.UtcDateTime;
                    }
                    else
                    {
                        task.ScheduleType = (int)ScheduleTypes.Weekly;

                        if (staffingScheduleInput.Spt.Contains("AM") || staffingScheduleInput.Spt.Contains("PM"))
                        {
                            task.Time = staffingScheduleInput.Spt;
                        }
                        else
                        {
                            var    timeFromInput = DateTime.ParseExact(staffingScheduleInput.Spt, "H:m", null, DateTimeStyles.None);
                            string time12Hour    = timeFromInput.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));

                            task.Time = time12Hour;
                        }
                    }

                    task.Sunday    = staffingScheduleInput.Sun;
                    task.Monday    = staffingScheduleInput.Mon;
                    task.Tuesday   = staffingScheduleInput.Tue;
                    task.Wednesday = staffingScheduleInput.Wed;
                    task.Thursday  = staffingScheduleInput.Thu;
                    task.Friday    = staffingScheduleInput.Fri;
                    task.Saturday  = staffingScheduleInput.Sat;
                    task.AddedOn   = DateTime.UtcNow;
                    task.Active    = true;
                    task.Data      = staffingScheduleInput.Ste;
                    task.TaskType  = (int)TaskTypes.UserStaffingLevel;
                    task.Note      = staffingScheduleInput.Not;

                    var saved = await _scheduledTasksService.SaveScheduledTaskAsync(task, cancellationToken);

                    return(CreatedAtAction(nameof(CreateStaffingSchedule), new { id = saved.IdValue }, saved));
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }