public async Task <List <ChangeDescriptorDto> > GetModelChangesAsync(GroupModel original, GroupModel model) { var changes = ReflectionHelper.DetectGroupChanges(model, original); var retVal = new List <ChangeDescriptorDto>(); foreach (var change in changes) { if (_cachedLookupService.IsLookupField(change.Name)) { change.OldValue = await _cachedLookupService.GetNameAsync(change.Name, change.OldValue.ToInteger()); change.NewValue = await _cachedLookupService.GetNameAsync(change.Name, change.NewValue.ToInteger()); } if (change.DisplayName == null) { change.DisplayName = PropertyName2Label(change.Name); } retVal.Add(new ChangeDescriptorDto { Id = change.Name, Name = change.DisplayName ?? change.Name, NewValue = change.NewValue.Clean(), OldValue = change.OldValue.Clean(), Tag = change.Tag, RequiresApproval = false }); } return(retVal); }
public async Task <List <ChangeDescriptorDto> > GetModelChangesAsync(EstablishmentModel original, EstablishmentModel model) { var changes = ReflectionHelper.DetectChanges(model, original, typeof(IEBTModel)); var retVal = new List <ChangeDescriptorDto>(); foreach (var change in changes) { if (_cachedLookupService.IsLookupField(change.Name)) { change.OldValue = await _cachedLookupService.GetNameAsync(change.Name, change.OldValue.ToInteger()); change.NewValue = await _cachedLookupService.GetNameAsync(change.Name, change.NewValue.ToInteger()); } if (change.Name.EndsWith("Id", StringComparison.Ordinal)) { change.Name = change.Name.Substring(0, change.Name.Length - 2); } change.Name = change.Name.Replace("_", "").Replace(nameof(IEBTModel) + ".", string.Empty); change.Name = change.Name.ToProperCase(true); retVal.Add(new ChangeDescriptorDto { Name = change.DisplayName ?? change.Name, NewValue = change.NewValue.Clean(), OldValue = change.OldValue.Clean() }); } await DetectSENChanges(original, model, retVal); return(retVal); }
public async Task PopulateLayoutProperties(object viewModel, int?establishmentUrn, int?groupUId, IPrincipal user, Action <EstablishmentModel> processEstablishment = null, Action <GroupModel> processGroup = null) { if (establishmentUrn.HasValue && groupUId.HasValue) { throw new InvalidParameterException("Both urn and uid cannot be populated"); } if (!establishmentUrn.HasValue && !groupUId.HasValue) { throw new InvalidParameterException($"Both {nameof(establishmentUrn)} and {nameof(groupUId)} parameters are null"); } if (establishmentUrn.HasValue) { var domainModel = (await _establishmentReadService.GetAsync(establishmentUrn.Value, user)).GetResult(); var displayPolicy = await _establishmentReadService.GetDisplayPolicyAsync(domainModel, user); var permissibleGovernanceModes = await _establishmentReadService.GetPermissibleLocalGovernorsAsync(establishmentUrn.Value, user); if (!permissibleGovernanceModes.Any()) { domainModel.GovernanceModeId = null; // hack the model returned. } var vm = (IEstablishmentPageViewModel)viewModel; vm.Layout = EstabLayout; vm.Name = domainModel.Name; if (domainModel.TypeId.HasValue) { vm.TypeName = (await _cls.GetNameAsync(() => domainModel.TypeId)); } vm.SelectedTab = "governance"; vm.Urn = domainModel.Urn; vm.TabDisplayPolicy = new TabDisplayPolicy(domainModel, displayPolicy, user); vm.LegalParentGroup = EstablishmentController.GetLegalParent(vm.Urn.Value, await _groupReadService.GetAllByEstablishmentUrnAsync(vm.Urn.Value, user), user); // I agree, this shouldn't be a static. We should refector all this. We should have a base view model class. processEstablishment?.Invoke(domainModel); } else if (groupUId.HasValue) { var domainModel = (await _groupReadService.GetAsync(groupUId.Value, user)).GetResult(); var vm = (IGroupPageViewModel)viewModel; vm.Layout = GroupsLayout; vm.GroupName = domainModel.Name; vm.GroupTypeId = domainModel.GroupTypeId.Value; vm.GroupUId = groupUId; if (vm.GroupTypeId.HasValue) { vm.GroupTypeName = (await _cls.GetNameAsync(() => vm.GroupTypeId)); } vm.SelectedTabName = "governance"; vm.ListOfEstablishmentsPluralName = _nomenclatureService.GetEstablishmentsPluralName((eLookupGroupType)vm.GroupTypeId.Value); processGroup?.Invoke(domainModel); } }
public async Task <List <ChangeDescriptorDto> > GetModelChangesAsync(EstablishmentModel original, EstablishmentModel model, EstablishmentApprovalsPolicy approvalsPolicy) { var changes = ReflectionHelper.DetectChanges(model, original, new[] { typeof(IEBTModel), typeof(ProprietorModel) }); changes.AddRange(await DetectAdditionalAddressChanges(original, model)); changes.AddRange(await DetectProprietorsChanges(original, model)); var retVal = new List <ChangeDescriptorDto>(); var approvalFields = approvalsPolicy.GetFieldsRequiringApproval(); foreach (var change in changes) { if (_cachedLookupService.IsLookupField(change.Name)) { change.OldValue = await _cachedLookupService.GetNameAsync(change.Name, change.OldValue.ToInteger()); change.NewValue = await _cachedLookupService.GetNameAsync(change.Name, change.NewValue.ToInteger()); } if (change.DisplayName == null) { change.DisplayName = PropertyName2Label(change.Name); } retVal.Add(new ChangeDescriptorDto { Id = change.Name, Name = change.DisplayName ?? change.Name, NewValue = change.NewValue.Clean(), OldValue = change.OldValue.Clean(), Tag = change.Tag, RequiresApproval = (change.Tag == "additionaladdress" && approvalsPolicy.AdditionalAddresses.RequiresApproval) || //(change.Tag == "proprietors" && approvalsPolicy.IEBTDetail.Proprietors.RequiresApproval) || //(change.Name.Contains(nameof(approvalsPolicy.IEBTDetail.ChairOfProprietor)) && approvalsPolicy.IEBTDetail.ChairOfProprietor.RequiresApproval) || approvalFields.Contains(change.Name, StringComparer.OrdinalIgnoreCase), ApproverName = approvalsPolicy.GetApproverName(change.Name) }); } await DetectSENChanges(original, model, retVal); return(retVal); }
public async Task <string> GetAddressAsync(ICachedLookupService lookup) => StringUtil.ConcatNonEmpties(", ", Address_Line1, Address_Locality, Address_Line3, Address_CityOrTown, await lookup.GetNameAsync("CountyId", Address_CountyId), Address_PostCode);
public async Task <ActionResult> Details(int id, string searchQueryString = "", eLookupSearchSource searchSource = eLookupSearchSource.Groups, int skip = 0, string sortBy = null, bool saved = false) { ViewBag.ShowSaved = saved; var model = (await _groupReadService.GetAsync(id, User)).GetResult(); var viewModel = new GroupDetailViewModel { SearchQueryString = searchQueryString, SearchSource = searchSource, CanUserEdit = await _groupReadService.CanEditAsync(id, User), CanUserEditGovernance = await _groupReadService.CanEditGovernanceAsync(id, User), Group = model, GroupTypeName = model.GroupTypeId.HasValue ? await _lookup.GetNameAsync(() => model.GroupTypeId) : null, LocalAuthorityName = model.LocalAuthorityId.HasValue ? await _lookup.GetNameAsync(() => model.LocalAuthorityId) : null, GroupStatusName = model.StatusId.HasValue ? await _lookup.GetNameAsync(() => model.StatusId, "Group") : null, Address = model.GroupTypeId.OneOfThese(GT.SingleacademyTrust, GT.MultiacademyTrust, GT.ChildrensCentresGroup) ? model.Address.ToString() : null, IsUserLoggedOn = User.Identity.IsAuthenticated, GroupTypeId = model.GroupTypeId ?? -1, IsClosed = model.StatusId == (int)eLookupGroupStatus.Closed || model.StatusId == (int)eLookupGroupStatus.CreatedInError, IsClosedInError = model.StatusId == (int)eLookupGroupStatus.CreatedInError, CloseDate = model.ClosedDate }; if (viewModel.IsUserLoggedOn) { viewModel.ChangeHistory = await _groupReadService.GetChangeHistoryAsync(id, skip, 100, sortBy.Clean() ?? "requestedDateUtc-desc", User); } await PopulateEstablishmentList(viewModel.Establishments, model.GroupUId.Value, true); return(View(viewModel)); }
public async Task <ActionResult> Convert(ConvertSATViewModel viewModel) { if (viewModel.ActionName == "find" && ModelState.IsValid) { var result = (await _groupReadService.SearchByIdsAsync(viewModel.Text, viewModel.Text.ToInteger(), viewModel.Text, viewModel.Text.ToInteger(), User)).Items.FirstOrDefault(); if (result == null) { ModelState.AddModelError(nameof(viewModel.Text), "We were unable to find a single-academy trust matching those details"); } else if (result.StatusId == ((int)GS.Closed)) { ModelState.AddModelError(nameof(viewModel.Text), "Closed single-academy trusts can not be converted"); } else if (result.GroupTypeId != (int)GT.SingleacademyTrust) { ModelState.AddModelError(nameof(viewModel.Text), "That's an invalid group because it's of the wrong type."); } else { viewModel.Details = result; viewModel.CountryName = await _lookup.GetNameAsync(() => result.Address.CountryId); viewModel.CountyName = await _lookup.GetNameAsync(() => result.Address.CountyId); viewModel.Token = UriHelper.SerializeToUrlToken(result); } } else if (viewModel.ActionName == "confirm") { viewModel.Details = UriHelper.DeserializeUrlToken <SearchGroupDocument>(viewModel.Token); var apiResponse = await _groupWriteService.ConvertSAT2MAT(viewModel.Details.GroupUId, viewModel.CopyGovernanceInfo, User); if (apiResponse.HasErrors) { apiResponse.Errors.ForEach(x => ModelState.AddModelError("", x.GetMessage())); } else { TempData["ShowSaved"] = "saved"; return(RedirectToRoute("GroupDetails", new { id = apiResponse.GetResponse().Value })); } } return(View(viewModel)); }
public async Task <string> GetAltAddressAsync(ICachedLookupService lookup) => StringUtil.ConcatNonEmpties(", ", AltStreet, AltLocality, AltAddress3, AltTown, await lookup.GetNameAsync("CountyId", AltCountyId), AltPostCode);