public async Task <DefaultResponse <bool> > Post(ScheduleModel request)
 {
     return(await Handle <bool>(async() =>
     {
         return await Manager.AddSchedule(new AddScheduleCommand(request.UserId, request.ScheduleTime));
     }));
 }
Exemple #2
0
        public ActionResult Save(ScheduleEditViewModel viewModel)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (viewModel.Id.HasValue)
                    {
                        _scheduleManager.EditSchedule(viewModel.Id.Value, viewModel.ResponsibleId.Value, viewModel.StartAt.Value, viewModel.EndAt.Value);
                    }
                    else
                    {
                        _scheduleManager.AddSchedule(viewModel.ResponsibleId.Value, viewModel.StartAt.Value, viewModel.EndAt.Value);
                    }

                    return(RedirectToAction(nameof(Index)));
                }

                viewModel.People = _personManager.GetPersonList().OrderBy(p => p.Name).ToList();

                return(View(nameof(Edit), viewModel));
            } catch (Exception exc) {
                ModelState.AddModelError("", exc.Message);

                viewModel.People = _personManager.GetPersonList().OrderBy(p => p.Name).ToList();

                return(View(nameof(Edit), viewModel));
            }
        }
        public ActionResult ScheduleAssign(SpecialSchedule sch)
        {
            sch.RouteId = routeManager.GetRoute().FirstOrDefault(r => r.FromCityId == sch.FromCityId && r.ToCityId == sch.ToCityId).RouteID;
            Schedule newSchedule = new Schedule();

            newSchedule.ArrivalTime    = sch.ArrivalTime;
            newSchedule.DepartureTime  = sch.DepartureTime;
            newSchedule.DurationInMins = sch.DurationInMins;
            newSchedule.RouteId        = sch.RouteId;
            newSchedule.FlightID       = sch.FlightID;
            newSchedule.IsActive       = sch.IsActive;
            schMgr.AddSchedule(newSchedule);
            return(RedirectToAction("Index"));
        }
        // This event handler is fired when the "Sign-up for Activity" button is pushed.
        // This will add a schedule for the user to volunteer for.
        private void BtnSignupActivity_Click(object sender, RoutedEventArgs e)
        {
            // check to see if the user has a list item selected and gives a prompt if
            // they did not
            if (dgVolunteerActivities.SelectedItem == null)
            {
                MessageBox.Show("You must make a volunteering selection.");
                return;
            }
            else
            {
                // Checks to make sure the user is not already signed up for this activity
                List <ActivityVM> activities = _activityManager.RetrieveActivitiesByScheduleType(_user.PersonID, "Volunteer");
                foreach (ActivityVM a in activities)
                {
                    if (a.ActivityID == ((ActivityVM)dgVolunteerActivities.SelectedItem).ActivityID)
                    {
                        MessageBox.Show("You are already signed up to volunteer for this activity");
                        return;
                    }
                }

                // This asks the user if they are sure they want to volunteer, and if they choose
                // will be signed up
                if (MessageBox.Show("Are you sure?", "Sign-up to Volunteer", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    ActivityVM activity = (ActivityVM)dgVolunteerActivities.SelectedItem;
                    Schedule   schedule = new Schedule()
                    {
                        PersonID         = _user.PersonID,
                        ActivityID       = activity.ActivityID,
                        Type             = "Volunteer",
                        ActivitySchedule = false,
                        Start            = activity.Start,
                        End = activity.End
                    };
                    if (_scheduleManager.AddSchedule(schedule))
                    {
                        MessageBox.Show("Volunteer Schedule added");
                        populateUserVolunteerActivities();
                        checkVolunteerStatus();
                    }
                }
            }
        }
        // This event handler is fired when the assign employee button is clicked. It assigns the chosen employees to the chosen activity.
        private void BtnAssignEmployee_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dgAllEmployees.SelectedItem == null)
                {
                    MessageBox.Show("You must make a selection from the All Employees list.");
                    return;
                }
                if (dgAllActivities.SelectedItem == null)
                {
                    MessageBox.Show("You must make a selection from the All Activities list.");
                    return;
                }
                foreach (PersonScheduleVM se in dgScheduledEmployees.Items)
                {
                    if (se.PersonID == ((User)dgAllEmployees.SelectedItem).PersonID)
                    {
                        MessageBox.Show("You must choose an employee that is not currently assigned to this activity.");
                        return;
                    }
                }
                Schedule schedule = new Schedule()
                {
                    ActivityID       = ((ActivityVM)dgAllActivities.SelectedItem).ActivityID,
                    ActivitySchedule = false,
                    PersonID         = ((User)dgAllEmployees.SelectedItem).PersonID,
                    End   = ((ActivityVM)dgAllActivities.SelectedItem).End,
                    Start = ((ActivityVM)dgAllActivities.SelectedItem).Start,
                    Type  = "Employee"
                };

                if (_scheduleManager.AddSchedule(schedule))
                {
                    MessageBox.Show(((User)dgAllEmployees.SelectedItem).FirstName + " " + ((User)dgAllEmployees.SelectedItem).LastName + " has been added to " + ((ActivityVM)dgAllActivities.SelectedItem).ActivityName);
                    //populateAllActivities();
                    populateEmployeesScheduled();
                    populateAllEmployees();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
            }
        }
Exemple #6
0
 /// <summary>
 /// Creator: Jordan Lindo
 /// Created: 4/8/2020
 /// Approver: Chase Schulte
 ///
 /// Generates a new schedule.
 /// </summary>
 /// <remarks>
 /// Updater: NA
 /// Updated: NA
 /// Update: NA
 ///
 /// </remarks>
 private void btnNewSchedule_Click(object sender, RoutedEventArgs e)
 {
     getBaseSchedule();
     if (_baseScheduleVM != null)
     {
         try
         {
             DateTime              startDate = getStartDate();
             ScheduleVM            vM        = _scheduleManager.GenerateSchedule(startDate, _baseScheduleVM.BaseScheduleLines);
             frmConfirmNewSchedule confirm   = new frmConfirmNewSchedule(_user, vM);
             if ((bool)confirm.ShowDialog())
             {
                 vM.ScheduleID = _scheduleManager.AddSchedule(vM);
                 _scheduleManager.AddScheduledHours(vM.ScheduleID);
                 getSchedules();
                 setCboDateRange();
             }
         }
         catch (Exception ex)
         {
             WPFErrorHandler.ErrorMessage(ex.Message);
         }
     }
 }
Exemple #7
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("Schedule");

            Schedule schedule = new Schedule();

            Route route = new Route();

            if (dpFromCity.Text.Equals("None") == true)
            {
                lblError.Text = "Select From City";
                dpFromCity.Focus();
            }
            else if (dpToCity.Text.Equals("None") == true)
            {
                lblError.Text = "Select To City";
                dpToCity.Focus();
            }
            else if (dpAirlineName.Text.Equals("None") == true)
            {
                lblError.Text = "Select Airline Name";
                dpAirlineName.Focus();
            }
            else if (dpFlightName.Text.Equals("None") == true)
            {
                lblError.Text = "Select Flight Name";
                dpFlightName.Focus();
            }
            else if (DropDownList1.Text.Equals("None") == true)
            {
                lblError.Text = "Select Departure Hours";
                DropDownList1.Focus();
            }
            else if (DropDownList2.Text.Equals("None") == true)
            {
                lblError.Text = "Select Departure Minutes";
                DropDownList2.Focus();
            }
            else if (DropDownList4.Text.Equals("None") == true)
            {
                lblError.Text = "Select Arrival Hours";
                DropDownList4.Focus();
            }
            else if (DropDownList5.Text.Equals("None") == true)
            {
                lblError.Text = "Select Arrival Minutes";
                DropDownList5.Focus();
            }
            else
            {
                City fromcity = new City();
                fromcity.CityId = long.Parse(dpFromCity.SelectedItem.Value);
                fromcity.Name   = dpFromCity.SelectedItem.Text;
                route.FromCity  = fromcity;

                City tocity = new City();
                tocity.CityId = long.Parse(dpToCity.SelectedItem.Value);
                tocity.Name   = dpToCity.SelectedItem.Text;
                route.ToCity  = tocity;

                schedule.RouteInfo = route;
                int routeID = scheduleManager.GetRouteID(schedule);
                schedule.RouteInfo.ID = routeID;
                if (routeID == 0)
                {
                    lblError.Text = "Select the Existing Route";
                    dpFromCity.Focus();
                }
                else
                {
                    TimeSpan t1 = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString());
                    TimeSpan t2 = TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString());
                    total            = int.Parse((t1 - t2).TotalMinutes.ToString());
                    txtDuration.Text = total.ToString();

                    Flight flight = new Flight();
                    flight.ID   = long.Parse(dpFlightName.SelectedItem.Value);
                    flight.Name = dpFlightName.SelectedItem.Text;

                    schedule.RouteInfo      = route;
                    schedule.FlightInfo     = flight;
                    schedule.DepartureTime  = TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString());
                    schedule.ArrivalTime    = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString());
                    schedule.DurationInMins = total;
                    schedule.IsActive       = chkStatus.Checked;

                    foreach (RepeaterItem item in Repeater1.Items)
                    {
                        Label   lblclassname = (Label)item.FindControl("ClassName");
                        TextBox txtcost      = (TextBox)item.FindControl("txtCostPerTicket");

                        if (txtcost.Text.Length == 0)
                        {
                            lblError.Text = "Flight Cost Can't be Empty";
                            txtcost.Focus();
                            break;
                        }
                        else
                        {
                            if (txtcost != null || lblclassname != null)
                            {
                                string classname = lblclassname.Text;
                                string val       = txtcost.Text;

                                FlightCost fc = new FlightCost();
                                fc.Class         = (TravelClass)Enum.Parse(typeof(TravelClass), classname);
                                fc.CostPerTicket = decimal.Parse(txtcost.Text);

                                schedule.AddFlightCost(fc);
                            }
                        }
                    }

                    try
                    {
                        scheduleManager.AddSchedule(schedule);
                        lblError.Text = "Schedule Added Successfully";
                    }
                    catch (ScheduleManagerException ex)
                    {
                        lblError.Text = ex.Message;
                    }
                }
            }
        }
Exemple #8
0
        public async Task <IActionResult> Post([FromBody] CreateScheduleViewModel request)
        {
            ParametersViewModel.VerifyParameterNameAvailability(request.Parameters);
            if (request == null)
            {
                ModelState.AddModelError("Save", "No data passed");
                return(BadRequest(ModelState));
            }

            //validate the cron expression
            if (!string.IsNullOrWhiteSpace(request.CRONExpression))
            {
                if (string.IsNullOrWhiteSpace(request.CRONExpressionTimeZone))
                {
                    request.CRONExpressionTimeZone = "UTC";
                }
                try
                {
                    CronExpression expression = CronExpression.Parse(request.CRONExpression, CronFormat.Standard);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Save", string.Concat("Invalid cron expression, ", ex.Message));
                    return(BadRequest(ModelState));
                }
            }

            Guid entityId = Guid.NewGuid();

            if (request.Id == null || !request.Id.HasValue || request.Id.Equals(Guid.Empty))
            {
                request.Id = entityId;
            }

            try
            {
                if (request.StartingType.ToLower() == "queuearrival")
                {
                    if (request.QueueId == null)
                    {
                        throw new EntityOperationException("Schedule of starting type \"QueueArrival\" must contain a Queue id");
                    }
                }

                Schedule newSchedule = _manager.AddSchedule(request);

                foreach (var parameter in request.Parameters ?? Enumerable.Empty <ParametersViewModel>())
                {
                    ScheduleParameter scheduleParameter = new ScheduleParameter
                    {
                        Name       = parameter.Name,
                        DataType   = parameter.DataType,
                        Value      = parameter.Value,
                        ScheduleId = entityId,
                        CreatedBy  = applicationUser?.UserName,
                        CreatedOn  = DateTime.UtcNow,
                        Id         = Guid.NewGuid()
                    };
                    _scheduleParameterRepository.Add(scheduleParameter);
                }

                var response = await base.PostEntity(newSchedule);

                _recurringJobManager.RemoveIfExists(newSchedule.Id?.ToString());

                if (request.IsDisabled == false && !request.StartingType.ToLower().Equals("manual"))//if schedule is not a manual starting type
                {
                    var jsonScheduleObj = JsonSerializer.Serialize <Schedule>(newSchedule);

                    _backgroundJobClient.Schedule(() => _hubManager.ScheduleNewJob(jsonScheduleObj),
                                                  new DateTimeOffset(newSchedule.StartDate.Value));
                }

                return(response);
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Exemple #9
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager");

            Schedule schedule = new Schedule();

            Route route = null;

            if (dpAirlineName.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Airline Name";
                dpAirlineName.Focus();
            }
            else if (dpFlightName.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Flight Name";
                dpFlightName.Focus();
            }
            else if (dpDepartHours.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Departure Hours";
                dpDepartHours.Focus();
            }
            else if (dpDepartMins.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Departure Minutes";
                dpDepartMins.Focus();
            }
            else if (dpArrivalHours.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Arrival Hours";
                dpArrivalHours.Focus();
            }
            else if (dpArrivalMins.Text.Equals("None") == true)
            {
                ctlAdminMaster.ErrorMessage = "Select Arrival Minutes";
                dpArrivalMins.Focus();
            }
            else
            {
                string rid = dpRoute.SelectedValue;
                if (rid.Equals("-1"))
                {
                    ctlAdminMaster.ErrorMessage = "Select a route";
                    return;
                }
                IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager();
                try
                {
                    List <Route> routes = routeManager.GetRoutes();
                    foreach (Route r in routes)
                    {
                        if (r.ID == Convert.ToInt32(rid))
                        {
                            route = r;
                            break;
                        }
                    }
                }
                catch (RouteManagerException ex)
                {
                    ctlAdminMaster.ErrorMessage = ex.Message;
                }


                schedule.RouteInfo = route;

                if (scheduleManager.GetRouteID(schedule) == 0)
                {
                    ctlAdminMaster.ErrorMessage = "Select the Existing Route";
                    //dpFromCity.Focus();
                }
                else
                {
                    TimeSpan t1 = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString());
                    TimeSpan t2 = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString());
                    total = int.Parse((t1 - t2).TotalMinutes.ToString());
                    if (total == 0)
                    {
                        ctlAdminMaster.ErrorMessage = "The departure time and the arrival time cannot be same";
                        return;
                    }

                    if (total < 0)
                    {
                        total = (24 * 60) + total;
                    }
                    txtDuration.Text = total.ToString();

                    Flight flight = new Flight();
                    flight.ID   = long.Parse(dpFlightName.SelectedItem.Value);
                    flight.Name = dpFlightName.SelectedItem.Text;

                    schedule.RouteInfo      = route;
                    schedule.FlightInfo     = flight;
                    schedule.DepartureTime  = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString());
                    schedule.ArrivalTime    = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString());
                    schedule.DurationInMins = total;
                    schedule.IsActive       = chkStatus.Checked;

                    foreach (RepeaterItem item in Repeater1.Items)
                    {
                        Label   lblclassname = (Label)item.FindControl("ClassName");
                        TextBox txtcost      = (TextBox)item.FindControl("txtCostPerTicket");
                        decimal cost         = 0;
                        try
                        {
                            cost = Convert.ToDecimal(txtcost.Text);
                        }
                        catch (FormatException)
                        {
                            ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value";
                            txtcost.Focus();
                            return;
                        }
                        if (cost <= 0)
                        {
                            ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value";
                            txtcost.Focus();
                            return;
                        }
                        else
                        {
                            if (txtcost != null || lblclassname != null)
                            {
                                string classname = lblclassname.Text;
                                string val       = txtcost.Text;

                                FlightCost fc = new FlightCost();
                                fc.Class         = (TravelClass)Enum.Parse(typeof(TravelClass), classname);
                                fc.CostPerTicket = decimal.Parse(txtcost.Text);

                                schedule.AddFlightCost(fc);
                            }
                        }
                    }

                    //Extracted from the loop preventing a potential exception
                    try
                    {
                        scheduleManager.AddSchedule(schedule);
                        ctlAdminMaster.ErrorMessage = "Schedule Added Successfully";
                        //Response.Redirect("~/Admin/Home.aspx");
                    }
                    catch (ScheduleManagerException ex)
                    {
                        ctlAdminMaster.ErrorMessage = ex.Message;
                    }
                }
            }
        }