Пример #1
0
        private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
        {
            //this.IsEnabled = true;
            JobAssignmentViewModel obj = (JobAssignmentViewModel)DataContext;

            obj.IsContractorSelected = true;
        }
Пример #2
0
 private void DataGrid_Selected(object sender, RoutedEventArgs e)
 {
     JobAssignmentViewModel obj = (JobAssignmentViewModel)DataContext;
     // obj.IsContractorSelected = true;
     DataGrid dg = (DataGrid)sender;
     // MessageBox.Show(dg.SelectedIndex.ToString());
 }
Пример #3
0
        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            JobAssignmentViewModel javm = (JobAssignmentViewModel)this.DataContext;

            javm.ContractorCollection.Clear();
            javm.FindContractor();
        }
        public async Task <IActionResult> VolunteerJobRemoval(JobAssignmentViewModel vm)
        {
            var user = await userManager.GetUserAsync(User);

            VolunteerRepository repo = new VolunteerRepository(configModel.ConnectionString);
            VolunteerJobModel   job;

            // This endpoint should only be accessible if the user is a staff member or if the user is trying to remove a job they have signed themselves up for
            if (user.VolunteerId != vm.VolunteerId && !User.IsInRole(UserHelpers.UserRoles.Staff.ToString()))
            {
                return(Utilities.ErrorJson("Unauthorized"));
            }

            // The first check is so we can skip a call to the database if the user is signing up for a job on their own - clearly the user id is valid in that case
            if (vm.VolunteerId != user.VolunteerId && repo.GetVolunteer(vm.VolunteerId) == null)
            {
                return(Utilities.ErrorJson("Invalid volunteer id"));
            }

            if (vm.Date == DateTime.MinValue)
            {
                return(Utilities.ErrorJson("Must specify a date"));
            }

            job = repo.GetVolunteerJob(vm.JobId, vm.Date);
            if (job == null)
            {
                return(Utilities.ErrorJson("Invalid volunteer job id"));
            }

            if (!repo.CheckSignedUpForJob(vm.JobId, vm.VolunteerId, vm.Date))
            {
                return(Utilities.ErrorJson("Not currently signed up for this job"));
            }

            if (job.CurrentNumber <= job.Min)
            {
                try
                {
                    await EmailHelpers.SendEmail("*****@*****.**", $"{vm.Date.ToString("dd/MM/yyyy")} - {job.Name} may be understaffed",
                                                 $"A cancellation has left {job.Name} with fewer than its minimum of {job.Min} volunteers signed up on {vm.Date.ToString("dd/MM/yyyy")}.", configModel.EmailOptions);
                }
                catch (Exception)
                {
                    // This is in case the email fails to send - we still want to cancel the job, since the email isn't critical
                }
            }

            try
            {
                repo.RemoveVolunteerJobAssignment(vm.VolunteerId, vm.JobId, vm.Date);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(Utilities.NoErrorJson());
        }
Пример #5
0
        private void DataGrid_LostFocus(object sender, RoutedEventArgs e)
        {
            JobAssignmentViewModel obj = (JobAssignmentViewModel)DataContext;
            DataGrid dg = (DataGrid)sender;

            MessageBox.Show(dg.SelectedIndex.ToString());
            if (dg.SelectedIndex > 0)
            {
                obj.IsContractorSelected = false;
            }
        }
        public async Task <IActionResult> VolunteerJobAssignment(JobAssignmentViewModel vm)
        {
            var user = await userManager.GetUserAsync(User);

            VolunteerRepository repo = new VolunteerRepository(configModel.ConnectionString);
            VolunteerJobModel   job;

            // This endpoint should only be accessible if the user is a staff member or if the user is trying to sign themselves up for a job
            if (user.VolunteerId != vm.VolunteerId && !User.IsInRole(UserHelpers.UserRoles.Staff.ToString()))
            {
                return(Utilities.ErrorJson("Unauthorized"));
            }

            if (vm.Date == DateTime.MinValue)
            {
                return(Utilities.ErrorJson("Must specify a date"));
            }

            if (vm.Date.DayOfWeek != DayOfWeek.Saturday)
            {
                return(Utilities.ErrorJson("Jobs can only be signed up for for Saturdays"));
            }

            // The first check is so we can skip a call to the database if the user is signing up for a job on their own - clearly the user id is valid in that case
            if (vm.VolunteerId != user.VolunteerId && repo.GetVolunteer(vm.VolunteerId) == null)
            {
                return(Utilities.ErrorJson("Invalid volunteer id"));
            }

            try
            {
                job = repo.GetVolunteerJob(vm.JobId, vm.Date);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            if (job == null)
            {
                return(Utilities.ErrorJson("Invalid volunteer job id"));
            }

            if (repo.CheckSignedUpForJob(vm.JobId, vm.VolunteerId, vm.Date))
            {
                return(Utilities.ErrorJson("Already signed up"));
            }

            if (job.CurrentNumber >= job.Max)
            {
                return(Utilities.ErrorJson("Too many people are already signed up for this job"));
            }

            try
            {
                repo.AddVolunteerJobAssignment(vm.VolunteerId, vm.JobId, vm.Date);
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(Utilities.NoErrorJson());
        }