Exemple #1
0
        public async Task <ActionResult> EditDetails(GroupEditorViewModel viewModel)
        {
            var result = await new GroupEditorViewModelValidator(_groupReadService, _establishmentReadService, User, _securityService).ValidateAsync(viewModel);

            result.AddToModelState(ModelState, string.Empty);

            await PopulateSelectLists(viewModel);

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

            await ValidateAsync(viewModel);

            if (ModelState.IsValid && !viewModel.WarningsToProcess.Any())
            {
                var actionResult = await ProcessCreateEditGroup(viewModel);

                if (actionResult != null)
                {
                    return(actionResult);
                }
            }

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

            return(View("EditDetails", viewModel));
        }
Exemple #2
0
        public async Task <ActionResult> Create(GroupEditorViewModel viewModel)
        {
            var result = await new GroupEditorViewModelValidator(_groupReadService, _establishmentReadService, User, _securityService).ValidateAsync(viewModel);

            result.AddToModelState(ModelState, string.Empty);

            await PopulateSelectLists(viewModel);

            await ValidateAsync(viewModel);

            if (ModelState.IsValid && !viewModel.WarningsToProcess.Any())
            {
                var actionResult = await ProcessCreateEditGroup(viewModel);

                if (actionResult != null)
                {
                    return(actionResult);
                }
            }

            if (viewModel.GroupTypeMode == eGroupTypeMode.ChildrensCentre)
            {
                return(View("CreateChildrensCentre", viewModel));
            }

            return(View("Create", viewModel));
        }
Exemple #3
0
        private async Task <GroupEditorViewModel> SetEditPermissions(GroupEditorViewModel viewModel)
        {
            viewModel.CanUserCloseAndMarkAsCreatedInError = viewModel.GroupType.OneOfThese(GT.MultiacademyTrust, GT.SingleacademyTrust, GT.SchoolSponsor) &&
                                                            !viewModel.StatusId.OneOfThese(GS.CreatedInError, GS.Closed) &&
                                                            User.InRole(AuthorizedRoles.IsAdmin);

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


            if (User.InRole(AuthorizedRoles.CanBulkAssociateEstabs2Groups) && viewModel.GroupType.OneOfThese(GT.MultiacademyTrust, GT.SingleacademyTrust))
            {
                viewModel.CanUserEditClosedDate = true;
                viewModel.CanUserEditStatus     = true;
                PopulateStatusSelectList(viewModel);
            }

            if (User.InRole(AuthorizedRoles.IsAdmin) &&
                viewModel.GroupType.OneOfThese(GT.MultiacademyTrust, GT.SingleacademyTrust))
            {
                viewModel.CanUserEditUkprn = true;
            }

            return(viewModel);
        }
Exemple #4
0
        public questStatus Read(GroupId groupId, out GroupEditorViewModel groupEditorViewModel)
        {
            // Initialize
            questStatus status = null;

            groupEditorViewModel = null;


            // Read
            Quest.Functional.ASM.Group group = null;
            GroupsMgr groupsMgr = new GroupsMgr(this.UserSession);

            status = groupsMgr.Read(groupId, out group);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            groupEditorViewModel = new GroupEditorViewModel(this.UserSession);
            BufferMgr.TransferBuffer(group, groupEditorViewModel);



            return(new questStatus(Severity.Success));
        }
Exemple #5
0
        private async Task EditLinkedEstablishment(GroupEditorViewModel viewModel)
        {
            var model = viewModel.LinkedEstablishments.Establishments.First(x => x.Urn == viewModel.ActionUrn);

            viewModel.LinkedEstablishments.LinkedEstablishmentSearch.Name       = model.Name;
            viewModel.LinkedEstablishments.LinkedEstablishmentSearch.FoundUrn   = model.Urn;
            viewModel.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate = new DateTimeViewModel(model.JoinedDate);
        }
Exemple #6
0
        public async Task <ActionResult> EditDetails(GroupEditorViewModel viewModel)
        {
            var result = await new GroupEditorViewModelValidator(_groupReadService, _establishmentReadService, User, _securityService).ValidateAsync(viewModel);

            result.AddToModelState(ModelState, string.Empty);

            await PopulateSelectLists(viewModel);

            if (viewModel.CanUserEditStatus)
            {
                PopulateStatusSelectList(viewModel);
            }

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

            await ValidateAsync(viewModel);

            if (ModelState.IsValid && !viewModel.WarningsToProcess.Any())
            {
                var dto     = CreateSaveDto(viewModel).Group;
                var changes = await _groupReadService.GetModelChangesAsync(dto, User);

                if (changes.Any() && viewModel.GroupTypeId.OneOfThese(GT.SingleacademyTrust, GT.MultiacademyTrust) && !viewModel.ChangesAcknowledged)
                {
                    viewModel.ChangesSummary = changes;
                    return(View("EditDetails", viewModel));
                }
                else
                {
                    var actionResult = await ProcessCreateEditGroup(viewModel);

                    if (actionResult != null)
                    {
                        return(actionResult);
                    }
                }
            }
            else
            {
                if (viewModel.GroupUId.HasValue)
                {
                    var domainModel = (await _groupReadService.GetAsync((int)viewModel.GroupUId, User)).GetResult();
                    viewModel.OriginalGroupName     = domainModel.Name;
                    viewModel.OriginalGroupTypeName = await _lookup.GetNameAsync(() => domainModel.GroupTypeId);
                }
            }

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

            return(View("EditDetails", viewModel));
        }
Exemple #7
0
        /// <summary>
        /// Does 2nd-level validation
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private async Task ValidateAsync(GroupEditorViewModel viewModel)
        {
            if (viewModel.Action == ActionSave && ModelState.IsValid)
            {
                var dto = CreateSaveDto(viewModel);
                var validationEnvelope = await _groupWriteService.ValidateAsync(dto, User);

                validationEnvelope.Errors.ForEach(x => ModelState.AddModelError(x.Fields ?? string.Empty, x.GetMessage()));
                viewModel.SetWarnings(validationEnvelope);
                ModelState.Remove(nameof(viewModel.ProcessedWarnings));
            }
        }
Exemple #8
0
        /// <summary>
        /// Does 2nd-level validation
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private async Task  ValidateAsync(GroupEditorViewModel viewModel)
        {
            if ((viewModel.Action == ActionSave ||
                 viewModel.Action == ActionDetails ||
                 viewModel.Action.StartsWith(ActionLinkedEstablishmentRemove) ||
                 viewModel.Action == ActionLinkedEstablishmentSearch ||
                 viewModel.Action == ActionLinkedEstablishmentAdd ||
                 viewModel.Action.StartsWith(ActionLinkedEstablishmentEdit) ||
                 viewModel.Action == ActionLinkedEstablishmentCancelEdit
                 ) && ModelState.IsValid)
            {
                var dto = CreateSaveDto(viewModel);
                var validationEnvelope = await _groupWriteService.ValidateAsync(dto, User);

                if (viewModel.Action.StartsWith(ActionLinkedEstablishmentRemove) ||
                    viewModel.Action == ActionLinkedEstablishmentSearch ||
                    viewModel.Action == ActionLinkedEstablishmentAdd ||
                    viewModel.Action.StartsWith(ActionLinkedEstablishmentEdit) ||
                    viewModel.Action == ActionLinkedEstablishmentCancelEdit)
                {
                    // ignore the message about the number of establishments in the group, as per JS behaviour
                    for (var i = 0; i < validationEnvelope.Errors.Count; i++)
                    {
                        if (validationEnvelope.Errors[i].Code.Equals("error.validation.link.cc.one.linked.school"))
                        {
                            validationEnvelope.Errors.RemoveAt(i);
                        }
                    }
                }

                if (viewModel.Action == ActionSave || viewModel.Action == ActionDetails)
                {
                    // we want to rebuild the screen once the removal has completed, so set the viewstate back to default
                    viewModel.ClearWarnings();
                }

                if (viewModel.Action.StartsWith(ActionLinkedEstablishmentRemove) || viewModel.Action == ActionLinkedEstablishmentCancelEdit)
                {
                    // we want to rebuild the screen once the removal has completed, so set the viewstate back to default
                    viewModel.ClearWarnings();
                    viewModel.ProcessedWarnings = false;
                }

                validationEnvelope.Errors.ForEach(x => ModelState.AddModelError(x.Fields?.Replace("Unmapped field: group.closedDate", nameof(viewModel.ClosedDate)) ?? string.Empty, x.GetMessage()));
                viewModel.SetWarnings(validationEnvelope);
                ModelState.Remove(nameof(viewModel.ProcessedWarnings));
            }
        }
Exemple #9
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));
        }
Exemple #10
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));
        }
Exemple #11
0
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        // CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus Save(GroupEditorViewModel groupEditorViewModel)
        {
            // Initialize
            questStatus status = null;


            // Transfer model
            Quest.Functional.ASM.Group group = new Quest.Functional.ASM.Group();
            BufferMgr.TransferBuffer(groupEditorViewModel, group);


            // Determine if this is a create or update
            GroupsMgr groupsMgr = new GroupsMgr(this.UserSession);

            if (groupEditorViewModel.Id < BaseId.VALID_ID)
            {
                // Create
                GroupId groupId = null;
                status = groupsMgr.Create(group, out groupId);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, groupEditorViewModel);
                    return(status);
                }
                groupEditorViewModel.Id = groupId.Id;
            }
            else
            {
                // Update
                status = groupsMgr.Update(group);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, groupEditorViewModel);
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
        public ActionResult Index()
        {
            var model = new GroupEditorModel()
            {
                Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                {
                    Grid = repo.ToBsGridViewModel(new BsGridRepositorySettings<ContributorSearchModel>
                    {
                        Page = 1,
                        PageSize = 10,
                        Search = new ContributorSearchModel
                        {
                            RolesFilter = new List<ProjectRole>() { ProjectRole.Developer, ProjectRole.TeamLeader }
                        }
                    }),
                    Search = repo.GetSearchForm(null),
                    New = repo.GetNewForm()
                },

                Testers = new ContributorsInheritExample
                {
                    Grid = repo.ToBsGridViewModel(new BsGridRepositorySettings<ContributorSearchModel>
                    {
                        Page = 1,
                        PageSize = 10,
                        Search = new ContributorSearchModel
                        {
                            RolesFilter = new List<ProjectRole>() { ProjectRole.Tester }
                        }
                    }),
                    Search = repo.GetSearchForm(null)
                },

                BFormsProject = new BsEditorGroupModel<ContributorsGroupRowModel, ContributorsRowFormModel>
                {
                    Items = new List<ContributorsGroupRowModel>()
                    {
                        new ContributorsGroupRowModel
                        {
                            Id = 1,
                            Name = "Stefan P.",
                            TabId = ContributorType.Developer,
                            Contributions = "concept, api design, razor helpers, documentation, c# bug fixing, testing",
                            Form = new ContributorsRowFormModel()
                            {
                                Contributions = "concept, api design, razor helpers, documentation, c# bug fixing, testing"
                            }
                        },
                        new ContributorsGroupRowModel
                        {
                            Id = 6,
                            Name = "Oana M.",
                            TabId = ContributorType.Developer,
                            Contributions = "UI & UX, css master",
                            Form = new ContributorsRowFormModel()
                            {
                                Contributions = "UI & UX, css master"
                            }
                        },
                         new ContributorsGroupRowModel
                        {
                            Id = 3,
                            Name = "Cezar C.",
                            TabId = ContributorType.Developer,
                            Contributions = "documentation, razor helpers",
                            Form = new ContributorsRowFormModel()
                            {
                                Contributions = "documentation, razor helpers"
                            }
                        },
                        new ContributorsGroupRowModel
                        {
                            Id = 4,
                            Name = "Marius C.",
                            TabId = ContributorType.Developer,
                            Contributions = "js framework, datetime picker, automated tests for js",
                            Form = new ContributorsRowFormModel()
                            {
                                Contributions = "js framework, datetime picker, automated tests for js"
                            }
                        }
                    },
                    Form = new ContributorsRowFormModel()
                },

                RequireJsProject = new BsEditorGroupModel<ContributorsGroupRowModel>
                {
                    Items = new List<ContributorsGroupRowModel>()
                    {
                        new ContributorsGroupRowModel
                        {
                            Id = 1,
                            Name = "Stefan P.",
                            Contributions = "concept, api design, razor helpers, documentation, c# bug fixing, testing",
                            TabId = ContributorType.Developer
                        },
                        new ContributorsGroupRowModel
                        {
                            Id = 3,
                            Name = "Cezar C.",
                            Contributions = "documentation, razor helpers",
                            TabId = ContributorType.Developer
                        }
                    }
                },
                Form = new GroupFormModel()
            };

            var viewModel = new GroupEditorViewModel
            {
                Editor = model
            };

            var options = new
            {
                getTabUrl = Url.Action("GetTab"),
                save = Url.Action("Save"),
                advancedSearchUrl = Url.Action("Search"),
                addUrl = Url.Action("New"),
                contributorType = RequireJsHtmlHelpers.ToJsonDictionary<ContributorType>(),
                projectRole = RequireJsHtmlHelpers.ToJsonDictionary<ProjectRole>()
            };

            RequireJsOptions.Add("index", options);

            return View(viewModel);
        }
        public string RenderTab(BsEditorRepositorySettings<ContributorType> settings, out int count)
        {
            var html = string.Empty;
            count = 0;

            GroupEditorModel model = new GroupEditorModel();

            if (settings.Search == null)
            {
                settings.Search = new ContributorSearchModel();
            }

            switch (settings.TabId)
            {
                case ContributorType.Developer:

                    ((ContributorSearchModel)settings.Search).RolesFilter = new List<ProjectRole>() { ProjectRole.Developer, ProjectRole.TeamLeader };

                    var gridDevelopers = repo.ToBsGridViewModel(settings.ToGridRepositorySettings<ContributorSearchModel>(), out count);

                    model.Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                    {
                        Grid = gridDevelopers
                    };

                    break;

                case ContributorType.Tester:

                    ((ContributorSearchModel)settings.Search).RolesFilter = new List<ProjectRole>() { ProjectRole.Tester };

                    var gridTesters = repo.ToBsGridViewModel(settings.ToGridRepositorySettings<ContributorSearchModel>(), out count);

                    model.Testers = new ContributorsInheritExample
                    {
                        Grid = gridTesters
                    };
                    break;
            }

            var viewModel = new GroupEditorViewModel()
            {
                Editor = model
            };

            html = this.BsRenderPartialView("_Editors", viewModel);

            return html;
        }
        public BsJsonResult New(ContributorNewModel model, ContributorType tabId)
        {
            var status = BsResponseStatus.Success;
            var row = string.Empty;
            var msg = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    var rowModel = repo.Create(model);

                    var groupEditorModel = new GroupEditorModel
                    {
                        Developers = new BsEditorTabModel<ContributorRowModel, ContributorSearchModel, ContributorNewModel>
                        {
                            Grid = new BsGridModel<ContributorRowModel>
                            {
                                Items = new List<ContributorRowModel>
                                {
                                    rowModel
                                }
                            }
                        }
                    };

                    var viewModel = new GroupEditorViewModel()
                    {
                        Editor = groupEditorModel
                    };

                    row = this.BsRenderPartialView("_Editors", viewModel);

                }
                else
                {
                    return new BsJsonResult(
                        new Dictionary<string, object> { { "Errors", ModelState.GetErrors() } },
                        BsResponseStatus.ValidationError);
                }
            }
            catch (Exception ex)
            {
                msg = Resource.ServerError;
                status = BsResponseStatus.ServerError;
            }

            return new BsJsonResult(new
            {
                Row = row
            }, status, msg);
        }