コード例 #1
0
        public async Task <ActionResult> EditLinks(int id, bool saved = false)
        {
            ViewBag.ShowSaved = saved;
            var domainModel = (await _groupReadService.GetAsync(id, User)).GetResult();
            var viewModel   = new GroupEditorViewModel
            {
                SaveMode    = eSaveMode.Links,
                GroupName   = domainModel.Name,
                GroupUId    = domainModel.GroupUId,
                GroupTypeId = domainModel.GroupTypeId
            };

            await PopulateEstablishmentList(viewModel.LinkedEstablishments.Establishments, id, true);

            viewModel.ListOfEstablishmentsPluralName = _nomenclatureService.GetEstablishmentsPluralName((GT)viewModel.GroupTypeId.Value);
            viewModel.SelectedTabName = "links";

            viewModel.DeriveCCLeadCentreUrn();

            if (viewModel.GroupTypeId.HasValue)
            {
                viewModel.GroupTypeName = (await _lookup.GetNameAsync(() => viewModel.GroupTypeId));
            }

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <ActionResult> EditDetails(int id)
        {
            var domainModel = (await _groupReadService.GetAsync(id, User)).GetResult();
            var viewModel   = new GroupEditorViewModel(eSaveMode.Details)
            {
                Address              = domainModel.Address.ToString(),
                AddressJsonToken     = UriHelper.SerializeToUrlToken(domainModel.Address),
                ClosedDate           = new DateTimeViewModel(domainModel.ClosedDate),
                OpenDate             = new DateTimeViewModel(domainModel.OpenDate),
                LocalAuthorityId     = domainModel.LocalAuthorityId,
                GroupTypeId          = domainModel.GroupTypeId,
                ManagerEmailAddress  = domainModel.ManagerEmailAddress,
                GroupName            = domainModel.Name,
                CompaniesHouseNumber = domainModel.CompaniesHouseNumber,
                GroupUId             = domainModel.GroupUId,
                GroupId              = domainModel.GroupId,
                SelectedTabName      = "details",
                StatusId             = domainModel.StatusId
            };

            viewModel.ListOfEstablishmentsPluralName = _nomenclatureService.GetEstablishmentsPluralName((GT)viewModel.GroupTypeId.Value);

            await PopulateEstablishmentList(viewModel.LinkedEstablishments.Establishments, id, true);
            await PopulateSelectLists(viewModel);

            viewModel.LocalAuthorityName = await _lookup.GetNameAsync(() => viewModel.LocalAuthorityId);

            viewModel.DeriveCCLeadCentreUrn();

            if (viewModel.GroupTypeId.HasValue)
            {
                viewModel.GroupTypeName = (await _lookup.GetNameAsync(() => viewModel.GroupTypeId));
            }

            viewModel.CanUserCloseMATAndMarkAsCreatedInError = viewModel.GroupType.OneOfThese(GT.MultiacademyTrust) &&
                                                               !viewModel.StatusId.OneOfThese(GS.CreatedInError, GS.Closed) &&
                                                               User.InRole(EdubaseRoles.ROLE_BACKOFFICE);

            viewModel.IsLocalAuthorityEditable = viewModel.GroupTypeId.OneOfThese(GT.ChildrensCentresCollaboration, GT.ChildrensCentresGroup) &&
                                                 viewModel.LinkedEstablishments.Establishments.Count == 0 && User.InRole(EdubaseRoles.ROLE_BACKOFFICE);

            return(View("EditDetails", viewModel));
        }
コード例 #3
0
        public async Task <ActionResult> EditDetails(int id)
        {
            var domainModel = (await _groupReadService.GetAsync(id, User)).GetResult();
            var viewModel   = new GroupEditorViewModel(eSaveMode.Details)
            {
                Address              = domainModel.Address.ToString(),
                AddressJsonToken     = UriHelper.SerializeToUrlToken(domainModel.Address),
                ClosedDate           = new DateTimeViewModel(domainModel.ClosedDate),
                OpenDate             = new DateTimeViewModel(domainModel.OpenDate),
                LocalAuthorityId     = domainModel.LocalAuthorityId,
                GroupTypeId          = domainModel.GroupTypeId,
                ManagerEmailAddress  = domainModel.ManagerEmailAddress,
                GroupName            = domainModel.Name,
                CompaniesHouseNumber = domainModel.CompaniesHouseNumber,
                GroupUId             = domainModel.GroupUId,
                GroupId              = domainModel.GroupId,
                SelectedTabName      = "details",
                StatusId             = domainModel.StatusId,
                OriginalStatusId     = domainModel.StatusId,
                UKPRN = domainModel.UKPRN.ToInteger()
            };

            viewModel.ListOfEstablishmentsPluralName = _nomenclatureService.GetEstablishmentsPluralName((GT)viewModel.GroupTypeId.Value);

            await PopulateEstablishmentList(viewModel.LinkedEstablishments.Establishments, id, true);
            await PopulateSelectLists(viewModel);

            viewModel.LocalAuthorityName = await _lookup.GetNameAsync(() => viewModel.LocalAuthorityId);

            viewModel.DeriveCCLeadCentreUrn();

            if (viewModel.GroupTypeId.HasValue)
            {
                viewModel.GroupTypeName = await _lookup.GetNameAsync(() => viewModel.GroupTypeId);
            }

            await SetEditPermissions(viewModel);

            return(View("EditDetails", viewModel));
        }
コード例 #4
0
        private async Task <ActionResult> ProcessCreateEditGroup(GroupEditorViewModel viewModel)
        {
            var suppressClearModelState = false;

            if (viewModel.Action == ActionLinkedEstablishmentAdd)
            {
                await AddLinkedEstablishment(viewModel);
            }
            else if (viewModel.Action == ActionLinkedEstablishmentCancelEdit)
            {
                viewModel.LinkedEstablishments.Establishments.ForEach(x => x.EditMode = false);
            }
            else if (viewModel.Action.StartsWith(ActionLinkedEstablishmentEdit, StringComparison.OrdinalIgnoreCase))
            {
                var m = viewModel.LinkedEstablishments.Establishments.Single(x => x.Urn == viewModel.ActionUrn);
                m.SetEditMode().JoinedDateEditable = new DateTimeViewModel(m.JoinedDate);
            }
            else if (viewModel.Action.StartsWith(ActionLinkedEstablishmentRemove, StringComparison.OrdinalIgnoreCase))
            {
                var index = viewModel.LinkedEstablishments.Establishments.FindIndex(x => x.Urn == viewModel.ActionUrn);
                if (index >= 0)
                {
                    viewModel.LinkedEstablishments.Establishments.RemoveAt(index);
                }

                if (viewModel.LinkedEstablishments.Establishments.Any() && !viewModel.LinkedEstablishments.Establishments.Any(x => x.CCIsLeadCentre))
                {
                    viewModel.LinkedEstablishments.Establishments.First().CCIsLeadCentre = true;
                    viewModel.DeriveCCLeadCentreUrn();
                }
            }
            else if (viewModel.Action == ActionLinkedEstablishmentSave)
            {
                var model = viewModel.LinkedEstablishments.Establishments.First(x => x.EditMode == true);
                model.SetEditMode(false).JoinedDate = model.JoinedDateEditable.ToDateTime();
            }
            else if (viewModel.Action == ActionLinkedEstablishmentSearch)
            {
                await SearchForLinkedEstablishment(viewModel);
            }
            else if (viewModel.Action == ActionSaveLinks)
            {
                suppressClearModelState = true;
                var apiResponse = await SaveGroup(viewModel);

                if (apiResponse.HasErrors)
                {
                    apiResponse.Errors.ForEach(x => ModelState.AddModelError(x.Fields, x.GetMessage()));
                }
                else
                {
                    return(new RedirectResult(Url.Action(nameof(Details)) + "#list"));
                    //return RedirectToAction(nameof(Details) , new { id = viewModel.GroupUId.Value, saved = true } );
                }
            }
            else if (viewModel.Action == ActionSave || viewModel.Action == ActionDetails)
            {
                suppressClearModelState = true;
                var apiResponse = await SaveGroup(viewModel);

                if (apiResponse.HasErrors)
                {
                    apiResponse.Errors.ForEach(x => ModelState.AddModelError(x.Fields, x.GetMessage()));
                }
                else
                {
                    return(RedirectToAction(nameof(Details), new { id = viewModel.GroupUId.Value, saved = true }));
                }
            }
            else if (viewModel.Action == ActionCcCreate)
            {
                viewModel.GroupTypeName = viewModel.GroupTypeId.HasValue
                    ? await _lookup.GetNameAsync(() => viewModel.GroupTypeId)
                    : null;
            }
            else
            {
                throw new InvalidParameterException("The action parameter is invalid");
            }

            if (!suppressClearModelState)
            {
                ModelState.Clear();
            }

            return(null);
        }
コード例 #5
0
        private SaveGroupDto CreateSaveDto(GroupEditorViewModel viewModel)
        {
            viewModel.SetCCLeadCentreUrn();

            GroupModel createDomainModel() => new GroupModel
            {
                CompaniesHouseNumber = viewModel.CompaniesHouseNumber,
                GroupId             = viewModel.GroupId,
                GroupTypeId         = viewModel.GroupTypeId,
                GroupUId            = viewModel.GroupUId,
                LocalAuthorityId    = viewModel.LocalAuthorityId,
                ManagerEmailAddress = viewModel.ManagerEmailAddress,
                Name       = viewModel.GroupName,
                OpenDate   = viewModel.OpenDate.ToDateTime(),
                ClosedDate = viewModel.ClosedDate.ToDateTime(),
                Address    = UriHelper.TryDeserializeUrlToken <AddressDto>(viewModel.AddressJsonToken),
                StatusId   = viewModel.StatusId,
                UKPRN      = viewModel.UKPRN?.ToString()
            };

            List <LinkedEstablishmentGroup> createLinksDomainModel()
            {
                var domainList = viewModel.LinkedEstablishments.Establishments.Select(x => new LinkedEstablishmentGroup
                {
                    Urn            = x.Urn,
                    Id             = x.Id,
                    JoinedDate     = x.JoinedDate ?? x.JoinedDateEditable.ToDateTime(),
                    CCIsLeadCentre = x.CCIsLeadCentre
                }).ToList();

                if (domainList.Any() && !domainList.Any(x => x.CCIsLeadCentre))
                {
                    domainList.First().CCIsLeadCentre = true;
                    viewModel.LinkedEstablishments.Establishments.First().CCIsLeadCentre = true;
                }
                return(domainList);
            }

            List <LinkedEstablishmentGroup> createLinkedEstablishmentFromSearch(bool isSearch = false) => new List <LinkedEstablishmentGroup>
            {
                new LinkedEstablishmentGroup
                {
                    Urn        = viewModel.LinkedEstablishments.LinkedEstablishmentSearch.Urn.ToInteger(),
                    JoinedDate =
                        viewModel.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate
                        .ToDateTime() ?? viewModel.OpenDate.ToDateTime(),
                    CCIsLeadCentre = isSearch || !createLinksDomainModel().Any(x => x.CCIsLeadCentre)
                }
            };

            List <LinkedEstablishmentGroup> createLinkedEstablishmentFromEdit() => new List <LinkedEstablishmentGroup>
            {
                new LinkedEstablishmentGroup
                {
                    Urn            = viewModel.LinkedEstablishments.Establishments.First(x => x.Urn == viewModel.ActionUrn).Urn,
                    JoinedDate     = viewModel.LinkedEstablishments.Establishments.First(x => x.Urn == viewModel.ActionUrn).JoinedDate,
                    CCIsLeadCentre = true // the validation always needs this to be set to true when in edit
                }
            };

            List <LinkedEstablishmentGroup> createLinkedEstablishmentFromAdd()
            {
                var domainList = createLinksDomainModel();

                if (domainList.Any(x => x.Urn == viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn))
                {
                    // edit
                    domainList.First(x => x.Urn == viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn)
                    .JoinedDate = viewModel.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate.ToDateTime();

                    viewModel.LinkedEstablishments.Establishments.First(x =>
                                                                        viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn != null &&
                                                                        x.Urn == viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn.Value).JoinedDate
                        = viewModel.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate.ToDateTime();
                }
                else
                {
                    // add
                    domainList.AddRange(createLinkedEstablishmentFromSearch(false));
                    if (viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn != null)
                    {
                        viewModel.LinkedEstablishments.Establishments.Add(new EstablishmentGroupViewModel
                        {
                            Name       = viewModel.LinkedEstablishments.LinkedEstablishmentSearch.Name,
                            JoinedDate =
                                viewModel.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate
                                .ToDateTime(),
                            Urn            = viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn.Value,
                            CCIsLeadCentre = viewModel.LinkedEstablishments.Establishments.All(x => x.CCIsLeadCentre == false)
                        });
                    }
                }
                viewModel.LinkedEstablishments.LinkedEstablishmentSearch = new LinkedEstablishmentSearchViewModel();
                return(domainList);
            }

            SaveGroupDto dto = null;

            if (viewModel.SaveMode == eSaveMode.Details)
            {
                dto = new SaveGroupDto(createDomainModel());
            }
            else if (viewModel.SaveMode == eSaveMode.DetailsAndLinks)
            {
                if (viewModel.Action == ActionLinkedEstablishmentSearch)
                {
                    dto = new SaveGroupDto(createDomainModel(), createLinkedEstablishmentFromSearch(true));
                    _   = SearchForLinkedEstablishment(viewModel);
                }
                else if (viewModel.Action.StartsWith(ActionLinkedEstablishmentEdit))
                {
                    dto = new SaveGroupDto(createDomainModel(), createLinkedEstablishmentFromEdit());
                    _   = EditLinkedEstablishment(viewModel);
                }
                else if (viewModel.Action == ActionLinkedEstablishmentAdd)
                {
                    dto = new SaveGroupDto(createDomainModel(), createLinkedEstablishmentFromAdd());
                }
                else if (viewModel.Action.StartsWith(ActionLinkedEstablishmentRemove))
                {
                    viewModel.LinkedEstablishments.Establishments.RemoveAll(x => x.Urn == viewModel.ActionUrn);
                    dto = new SaveGroupDto(createDomainModel(), createLinksDomainModel());
                }
                else
                {
                    dto = new SaveGroupDto(createDomainModel(), createLinksDomainModel());
                }
            }
            else if (viewModel.SaveMode == eSaveMode.Links)
            {
                dto = new SaveGroupDto(viewModel.GroupUId.Value, createLinksDomainModel());
            }
            else
            {
                throw new NotImplementedException($"SaveMode '{viewModel.SaveMode}' is not supported");
            }

            if (viewModel.CanUserCloseAndMarkAsCreatedInError &&
                viewModel.CloseAndMarkAsCreatedInError &&
                dto.Group != null)
            {
                dto.Group.StatusId = (int)GS.CreatedInError;
            }

            viewModel.DeriveCCLeadCentreUrn();

            return(dto);
        }