Example #1
0
        public async Task <IActionResult> CriteriaDetail(int id)
        {
            try
            {
                PageTitle = "Drawing Criteria";
                var criterion = await _drawingService.GetCriterionDetailsAsync(id);

                var branchList = await _siteService.GetBranches(1);

                var site = await GetCurrentSiteAsync();

                CriterionDetailViewModel viewModel = new CriterionDetailViewModel()
                {
                    Criterion     = criterion,
                    BranchList    = new SelectList(branchList.ToList(), "Id", "Name"),
                    ReadABook     = criterion.ActivityAmount.HasValue,
                    EligibleCount = await _drawingService.GetEligibleCountAsync(id)
                };
                return(View(viewModel));
            }
            catch (GraException gex)
            {
                ShowAlertWarning("Unable to view criteria: ", gex);
                return(RedirectToAction("Criteria"));
            }
        }
Example #2
0
        public async Task <IActionResult> CriteriaCreate(CriterionDetailViewModel model,
                                                         string Drawing)
        {
            if (ModelState.IsValid)
            {
                if (model.ReadABook)
                {
                    model.Criterion.PointTranslationId = 1;
                    model.Criterion.ActivityAmount     = 1;
                }
                var criterion = await _drawingService.AddCriterionAsync(model.Criterion);

                AlertSuccess = ($"Criteria <strong>{criterion.Name}</strong> created");
                if (string.IsNullOrWhiteSpace(Drawing))
                {
                    return(RedirectToAction("CriteriaDetail", new { id = criterion.Id }));
                }
                else
                {
                    return(RedirectToAction("New", new { id = criterion.Id }));
                }
            }
            else
            {
                PageTitle = "Drawing Criteria";
                var brancList = await _siteService.GetBranches(1);

                model.BranchList = new SelectList(brancList.ToList(), "Id", "Name");
                return(View(model));
            }
        }
Example #3
0
        public async Task <IActionResult> CriteriaCreate()
        {
            PageTitle = "Drawing Criteria";

            CriterionDetailViewModel viewModel = new CriterionDetailViewModel()
            {
                SystemList  = new SelectList((await _siteService.GetSystemList()), "Id", "Name"),
                BranchList  = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"),
                ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"),
            };

            return(View(viewModel));
        }
Example #4
0
        public async Task <IActionResult> CriteriaCreate()
        {
            PageTitle = "Drawing Criteria";

            var brancList = await _siteService.GetBranches(1);

            CriterionDetailViewModel viewModel = new CriterionDetailViewModel()
            {
                BranchList = new SelectList(brancList.ToList(), "Id", "Name")
            };

            return(View(viewModel));
        }
Example #5
0
        public async Task <IActionResult> CriteriaDetail(int id)
        {
            try
            {
                PageTitle = "Drawing Criteria";
                var criterion = await _drawingService.GetCriterionDetailsAsync(id);

                if (criterion.ProgramId.HasValue)
                {
                    criterion.ProgramIds.Add(criterion.ProgramId.Value);
                }
                var site = await GetCurrentSiteAsync();

                var programs = await _siteService.GetProgramList();

                CriterionDetailViewModel viewModel = new CriterionDetailViewModel()
                {
                    Criterion           = criterion,
                    CreatedByName       = await _userService.GetUsersNameByIdAsync(criterion.CreatedBy),
                    CanViewParticipants = UserHasPermission(Permission.ViewParticipantDetails),
                    SystemList          = new SelectList(await _siteService.GetSystemList(), "Id", "Name"),
                    ProgramList         = new SelectList(programs, "Id", "Name"),
                    EligibleCount       = await _drawingService.GetEligibleCountAsync(id),
                    ProgramPlaceholder  = string.Join(", ", programs
                                                      .Where(_ => criterion.ProgramIds.Contains(_.Id))
                                                      .Select(_ => _.Name))
                };

                if (viewModel.Criterion.SystemId.HasValue)
                {
                    viewModel.BranchList = new SelectList(
                        await _siteService.GetBranches(viewModel.Criterion.SystemId.Value), "Id", "Name");
                }
                else
                {
                    viewModel.BranchList = new SelectList(await _siteService.GetAllBranches(), "Id", "Name");
                }
                return(View(viewModel));
            }
            catch (GraException gex)
            {
                ShowAlertWarning("Unable to view criteria: ", gex);
                return(RedirectToAction("Criteria"));
            }
        }
Example #6
0
        public async Task <IActionResult> CriteriaDetail(CriterionDetailViewModel model,
                                                         string Drawing)
        {
            if (ModelState.IsValid)
            {
                if (model.Criterion.ProgramIds?.Count() == 1)
                {
                    model.Criterion.ProgramId  = model.Criterion.ProgramIds.First();
                    model.Criterion.ProgramIds = null;
                }
                else
                {
                    model.Criterion.ProgramId = null;
                }

                var criterion = await _drawingService.EditCriterionAsync(model.Criterion);

                AlertSuccess = ($"Criteria <strong>{criterion.Name}</strong> saved");
                if (string.IsNullOrWhiteSpace(Drawing))
                {
                    return(RedirectToAction("CriteriaDetail", new { id = criterion.Id }));
                }
                else
                {
                    return(RedirectToAction("New", new { id = criterion.Id }));
                }
            }
            else
            {
                PageTitle        = "Drawing Criteria";
                model.SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name");
                if (model.Criterion.SystemId.HasValue)
                {
                    model.BranchList = new SelectList(
                        (await _siteService.GetBranches(model.Criterion.SystemId.Value)), "Id", "Name");
                }
                else
                {
                    model.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name");
                }
                model.ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name");
                return(View(model));
            }
        }