private void SetFlagsFalse(StaffApplicationAdminVM model) { model.IsExitConfirmed = "False"; //Stop the binder resetting the posted values ModelState.Remove("IsExitConfirmed"); }
private StaffApplicationAdminVM ConvertSecurityCheckDC(StaffApplicationAdminVMDC returnedObject) { StaffApplicationAdminVM model = new StaffApplicationAdminVM(); RepopulateListsFromCacheSession(model); return(model); }
private void AddListsToSession(StaffApplicationAdminVM model) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* SessionManager.ApplicationList = model.ApplicationList; SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; SessionManager.StaffRoleList = model.RoleList; }
private static void ClearSesssionObjects(StaffApplicationAdminVM model) { //remove the current values from session SessionManager.OrganisationByTypeList = null; SessionManager.StaffApplicationAttributeList = null; SessionManager.StaffOrganisationList = null; SessionManager.ApplicationList = null; SessionManager.StaffRoleList = null; }
private void RepopulateListsFromCacheSession(StaffApplicationAdminVM model) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* model.ApplicationList = SessionManager.ApplicationList; model.OrganisationsByTypesList = SessionManager.OrganisationByTypeList; model.RoleList = SessionManager.StaffRoleList; model.StaffApplicationAttributeList = SessionManager.StaffApplicationAttributeList; model.StaffOrganisationList = SessionManager.StaffOrganisationList; //********************************* //* POPULATE CACHED LISTS * //********************************* }
private void DetermineIsDirty(StaffApplicationAdminVM model) { //Compare the attributes and organisations check to the original session db var changeSet = EstablishAdminChangeSet(model); if (changeSet.DeletedStaffAttributes.Count() + changeSet.DeletedStaffOrganisations.Count() + changeSet.InsertedStaffAttributes.Count() + changeSet.InsertedStaffOrganisations.Count() + changeSet.UpdatedStaffAttributes.Count() + changeSet.UpdatedStaffOrganisations.Count() == 0) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private StaffApplicationAdminVM GetUpdatedModel() { StaffApplicationAdminVM model = new StaffApplicationAdminVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (SessionManager.RootOrganisation != null) { model.RootNodeOrganisation = SessionManager.RootOrganisation; } if (SessionManager.CurrentApplicationCode != null) { model.SelectedApplicationCode = SessionManager.CurrentApplicationCode; } model.StaffItem = SessionManager.CurrentStaffForAdmin; //THERE IS A BUG IN THE WAY THE DEFAULT MODEL BINDER HANDLES COLLECTIONS IT DOESN'T UPDATE THE COLLECTION IT REPLACES IT WITH A NEW COLLECTION CONTAINING ONLY THE POSTED VALUES //MICROSOFT SHOULD HAVE CALLED IT TryCreateModel and not TryUpdateModel NOW I AM GOING TO HAVE TO RECONSTRUCT MY COLLECTION AGAIN // //SOLUTION: //i) Deliberately misname the collection in BeginCollectionItem in the partial view. The default binder will not be able to map this for the child view models //ii) Call the TryUpdate Model for each child item individually using the misnamed collection - this will map. //iii) Call the main TryUpdateModel Later and it won't overwrite what it can't map - //************************************************************************************************************************************************************ int i = 0; foreach (var item in model.OrganisationsByTypesList) { if (i != 0) { TryUpdateModel(item, "OrganisationsByRows[" + Request.Form["OrganisationsByRows.Index"].Split(',')[i - 1] + "]"); } i++; } //************************************************************************************************************************************************************8 //Need to loop around application attributes foreach (var item in model.StaffApplicationAttributeList) { //If there is an entry in the staff attributes string StaffAttributeValue = Request.Form["StaffAttributeValue_" + item.ApplicationAttributeItem.Code.ToString()]; if (!string.IsNullOrEmpty(StaffAttributeValue)) { if (item.ApplicationAttributeItem.AttributeType == "Bool") { //Convert 'on' to 'Yes' StaffAttributeValue = StaffAttributeValue == "on" ? "Yes" : "No"; } if (item.StaffAttributeItem != null) { item.StaffAttributeItem.LookupValue = StaffAttributeValue; } else { item.StaffAttributeItem = new StaffAttributesModel() { ApplicationAttributeCode = item.ApplicationAttributeItem.Code, ApplicationCode = item.ApplicationAttributeItem.ApplicationCode, Code = Guid.NewGuid(), IsActive = true, LookupValue = StaffAttributeValue, StaffCode = model.StaffItem.Code }; } } else //No entry in the staff attributes { if (item.StaffAttributeItem != null) { item.StaffAttributeItem = null; } } } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* #region Set the default organisation //NEED TO WORK OUT WHICH RADIO BUTTON IS SET FOR THE DEFAULT ORGANISATION Guid?selectedDefaultOrganisation = null; var defaultradio = Request.Form["defaultradio"]; if (defaultradio != null) { string DefaultStaffOrgCode = Request.Form["defaultradio"].Substring(32); selectedDefaultOrganisation = Guid.Parse(DefaultStaffOrgCode); } foreach (StaffOrganisationModel currentItem in model.StaffOrganisationList) { if (currentItem.Code == selectedDefaultOrganisation) { currentItem.IsDefault = true; } else { currentItem.IsDefault = false; } } #endregion return(model); }
private void ResolveFieldCodesToFieldNamesUsingLists(StaffApplicationAdminVM model) { }
private static void MergeReturnedObjectToModel(StaffApplicationAdminVM model, StaffApplicationAdminVMDC returnedObject) { model.StaffItem = Mapper.Map <StaffModel>(returnedObject.StaffItem); SessionManager.CurrentStaffForAdmin = model.StaffItem; //Clear the organisations list and repopulate from the returned object model.OrganisationsByTypesList.Clear(); List <OrganisationByTypeVM> AllOrganisationsForApplicationByTypesList = new List <OrganisationByTypeVM>(); foreach (var item in returnedObject.OrganisationsByTypesList) { AllOrganisationsForApplicationByTypesList.Add(new OrganisationByTypeVM() { OrganisationList = Mapper.Map <IEnumerable <OrganisationDC>, IEnumerable <OrganisationModel> >(item.OrganisationList).ToList(), OrganisationTypeItem = Mapper.Map <OrganisationTypeModel>(item.OrganisationTypeItem) }); } SessionManager.AllOrganisationsForApplicationByTypesList = AllOrganisationsForApplicationByTypesList; //initialise the available orgs, the first drop down should have THE ROOT ORGANISATION selected if (AllOrganisationsForApplicationByTypesList.Count > 1) { int i = 0; foreach (var item in AllOrganisationsForApplicationByTypesList) { if (i == 0) { model.OrganisationsByTypesList.Add(new OrganisationByTypeVM() { OrganisationList = item.OrganisationList, OrganisationTypeItem = item.OrganisationTypeItem, SelectedOrganisationCode = item.OrganisationList[0].Code.ToString() }); } else { model.OrganisationsByTypesList.Add(new OrganisationByTypeVM() { OrganisationList = !string.IsNullOrEmpty(model.OrganisationsByTypesList[i - 1].SelectedOrganisationCode) ? item.OrganisationList.Where(x => x.ParentID == Guid.Parse(model.OrganisationsByTypesList[i - 1].SelectedOrganisationCode)).ToList() : new List <OrganisationModel>(), OrganisationTypeItem = item.OrganisationTypeItem, SelectedOrganisationCode = "" }); } i++; } } //RoleList comes from the other service so don't merge it!!!!!!!!!!!!!!!!!! //model.RoleList = returnedObject.RoleList.ToList(); model.RootNodeOrganisation = Mapper.Map <OrganisationModel>(returnedObject.RootNodeOrganisation); model.SelectedApplicationCode = returnedObject.SelectedApplicationCode; //Clear the staff application attribute list and repopulate from the returned object model.StaffApplicationAttributeList.Clear(); foreach (var item in returnedObject.StaffApplicationAttributeList) { model.StaffApplicationAttributeList.Add(new StaffApplicationAttributeVM() { ApplicationAttributeItem = Mapper.Map <ApplicationAttributeModel>(item.ApplicationAttributeItem), StaffAttributeItem = Mapper.Map <StaffAttributesModel>(item.StaffAttributeItem) }); } model.StaffOrganisationList = Mapper.Map <IEnumerable <StaffOrganisationDC>, IEnumerable <StaffOrganisationModel> >(returnedObject.StaffOrganisationList).ToList(); //Add the values to session SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; List <StaffApplicationAttributeVM> SortedList = model.StaffApplicationAttributeList.OrderBy(x => x.ApplicationAttributeItem.AttributeName).ToList(); model.StaffApplicationAttributeList = SortedList; SessionManager.StaffApplicationAttributeList = model.StaffApplicationAttributeList; //Need to clone the staff attribute lists var AttributeDBList = new List <StaffApplicationAttributeVM>(); foreach (StaffApplicationAttributeVM item in model.StaffApplicationAttributeList) { AttributeDBList.Add(new StaffApplicationAttributeVM() { StaffAttributeItem = item.StaffAttributeItem.Clone(), ApplicationAttributeItem = item.ApplicationAttributeItem }); } SessionManager.StaffApplicationAttributeListDBVersion = AttributeDBList; SessionManager.StaffOrganisationList = model.StaffOrganisationList; //Need to clone all the items in the list and store them away as the current db version of the list var DBList = new List <StaffOrganisationModel>(); foreach (StaffOrganisationModel item in model.StaffOrganisationList) { DBList.Add(item.Clone()); } SessionManager.StaffOrganisationListDBVersion = DBList; SessionManager.StaffRoleList = model.RoleList; SessionManager.RootOrganisation = model.RootNodeOrganisation; }
public ActionResult ApplicationStaffAdmin(Guid?staffCode) { var model = new StaffApplicationAdminVM(); //Initialize lists model.OrganisationsByTypesList = new List <OrganisationByTypeVM>(); model.StaffApplicationAttributeList = new List <StaffApplicationAttributeVM>(); model.StaffOrganisationList = new List <StaffOrganisationModel>(); model.ApplicationList = new List <ApplicationModel>(); model.RoleList = new List <string>(); //Retreive staff item and application list model.StaffItem = SessionManager.CurrentStaff; //Retreive all applications that are available to the current user. try { string[] userRoles = SessionManager.UserRoles; var sc = new AdminServiceClient(); var ApplicationList = sc.GetApplicationsWithStaffAdmin(CurrentUser, CurrentUser, "Framework", "", userRoles, true); model.ApplicationList = Mapper.Map <IEnumerable <ApplicationDC>, IEnumerable <ApplicationModel> >(ApplicationList).ToList(); /* The following has been added to allow BCAS ADMINS to manage staff - limit the applications that be can be used - to be removed when generic solution is found * if (User.IsInRole(FrameworkRoles.BCASADMIN) && !User.IsInRole(FrameworkRoles.ADMIN) && !User.IsInRole(FrameworkRoles.STAFFMAINTENANCE)) * { * model.ApplicationList = model.ApplicationList.Where(x => x.ApplicationName == "BCAS").ToList(); * } */ } catch (Exception ex) { model.Message = FixedResources.MESSAGE_RETRIEVAL_FAILED; return(View(model)); } try { var sc1 = new AdminServiceClient(); var StaffItem = sc1.GetStaff(User.Identity.Name, User.Identity.Name, "Framework", "", SessionManager.StaffCode); model.StaffItem = Mapper.Map <StaffModel>(StaffItem.StaffItem); SessionManager.CurrentStaff = model.StaffItem; } catch (Exception ex) { model.Message = FixedResources.MESSAGE_RETRIEVAL_FAILED; return(View(model)); } //Initialize lists model.OrganisationsByTypesList = new List <OrganisationByTypeVM>(); model.StaffApplicationAttributeList = new List <StaffApplicationAttributeVM>(); model.StaffOrganisationList = new List <StaffOrganisationModel>(); SessionManager.CurrentStaffForAdmin = model.StaffItem; SessionManager.ApplicationList = model.ApplicationList; SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; SessionManager.StaffApplicationAttributeList = model.StaffApplicationAttributeList; SessionManager.StaffOrganisationList = model.StaffOrganisationList; SessionManager.StaffRoleList = model.RoleList; return(View(model)); }
private static StaffAdminChangeSetDC EstablishAdminChangeSet(StaffApplicationAdminVM model) { var changeSet = new StaffAdminChangeSetDC() { DeletedStaffAttributes = new StaffAttributesDC[0], DeletedStaffOrganisations = new StaffOrganisationDC[0], InsertedStaffAttributes = new StaffAttributesDC[0], InsertedStaffOrganisations = new StaffOrganisationDC[0], UpdatedStaffAttributes = new StaffAttributesDC[0], UpdatedStaffOrganisations = new StaffOrganisationDC[0], }; //Build a list of deleted organisations var StaffOrgsDB = SessionManager.StaffOrganisationListDBVersion; if (StaffOrgsDB != null && model.StaffOrganisationList != null) { var deletedStaffOrgs = new List <StaffOrganisationModel>(); foreach (var item in StaffOrgsDB) { if (!model.StaffOrganisationList.Any(x => x.Code == item.Code)) { deletedStaffOrgs.Add(item); } } //Build a list of changed organisations a new default org may have been set. var changedStaffOrgs = new List <StaffOrganisationModel>(); foreach (var item in model.StaffOrganisationList) { if (StaffOrgsDB.Any(x => x.Code == item.Code && x.IsDefault != item.IsDefault)) { changedStaffOrgs.Add(item); } } //Build list of added organisations var addedStaffOrgs = new List <StaffOrganisationModel>(); foreach (var item in model.StaffOrganisationList) { if (!StaffOrgsDB.Any(x => x.Code == item.Code)) { addedStaffOrgs.Add(item); } } changeSet.DeletedStaffOrganisations = Mapper.Map <IEnumerable <StaffOrganisationModel>, IEnumerable <StaffOrganisationDC> >(deletedStaffOrgs).ToArray(); changeSet.UpdatedStaffOrganisations = Mapper.Map <IEnumerable <StaffOrganisationModel>, IEnumerable <StaffOrganisationDC> >(changedStaffOrgs).ToArray(); changeSet.InsertedStaffOrganisations = Mapper.Map <IEnumerable <StaffOrganisationModel>, IEnumerable <StaffOrganisationDC> >(addedStaffOrgs).ToArray(); } //Build a list of deleted staff attributes var StaffAttributesDB = SessionManager.StaffApplicationAttributeListDBVersion; if (StaffAttributesDB != null && model.StaffApplicationAttributeList != null) { var deletedStaffAttrributes = new List <StaffAttributesModel>(); foreach (var item in StaffAttributesDB) { if (item.StaffAttributeItem != null) { if (!model.StaffApplicationAttributeList.Any(x => x.StaffAttributeItem != null && x.StaffAttributeItem.Code == item.StaffAttributeItem.Code)) { deletedStaffAttrributes.Add(item.StaffAttributeItem); } } } //Build a list of changed staff attributes var changedStaffAttrributes = new List <StaffAttributesModel>(); foreach (var item in model.StaffApplicationAttributeList) { if (item.StaffAttributeItem != null) { if (StaffAttributesDB.Any(x => x.StaffAttributeItem != null && x.StaffAttributeItem.Code == item.StaffAttributeItem.Code && x.StaffAttributeItem.LookupValue != item.StaffAttributeItem.LookupValue)) { changedStaffAttrributes.Add(item.StaffAttributeItem); } } } //Build a list of inserted staff attributes var addedStaffAttrributes = new List <StaffAttributesModel>(); foreach (var item in model.StaffApplicationAttributeList) { //var removeLater = item. if (item.StaffAttributeItem != null) { if (!StaffAttributesDB.Any(x => x.StaffAttributeItem != null && x.StaffAttributeItem.Code == item.StaffAttributeItem.Code)) { addedStaffAttrributes.Add(item.StaffAttributeItem); } } } changeSet.DeletedStaffAttributes = Mapper.Map <IEnumerable <StaffAttributesModel>, IEnumerable <StaffAttributesDC> >(deletedStaffAttrributes).ToArray(); changeSet.UpdatedStaffAttributes = Mapper.Map <IEnumerable <StaffAttributesModel>, IEnumerable <StaffAttributesDC> >(changedStaffAttrributes).ToArray(); changeSet.InsertedStaffAttributes = Mapper.Map <IEnumerable <StaffAttributesModel>, IEnumerable <StaffAttributesDC> >(addedStaffAttrributes).ToArray(); } return(changeSet); }