private static void MergeReturnedObjectToModel(ApplicationOrganisationAdminVM model, ApplicationOrganisationAdminVMDC returnedObject) { //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) { foreach (var item in AllOrganisationsForApplicationByTypesList) { model.OrganisationsByTypesList.Add(new OrganisationByTypeVM() { OrganisationList = item.OrganisationList, OrganisationTypeItem = item.OrganisationTypeItem, SelectedOrganisationCode = item.OrganisationList.SingleOrDefault(x => x.Code == model.ParentOrganisationCode) != null ? model.ParentOrganisationCode.ToString() : "" }); } } model.RootNodeOrganisation = Mapper.Map <OrganisationModel>(returnedObject.RootNodeOrganisation); //model.SelectedApplicationCode = returnedObject.SelectedApplicationCode; }
private void AddListsToSession(ApplicationOrganisationAdminVM model) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* //SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; SessionManager.AllTypesForApplication = model.AllTypesForApplication; }
private void SetApplicationOrganisationContext(ApplicationOrganisationAdminVM model) { if (model.OrganisationItem.OrganisationTypeCode != Guid.Empty) { if (model.AllTypesForApplication.Single(x => x.Code == model.OrganisationItem.OrganisationTypeCode).LevelNumber == 1) { ModelState.Remove("ParentOrganisationCode"); } } }
private void SetFlagsFalse(ApplicationOrganisationAdminVM model) { model.IsExitConfirmed = "False"; model.IsNewConfirmed = "False"; //Stop the binder resetting the posted values ModelState.Remove("IsDeleteConfirmed"); ModelState.Remove("IsExitConfirmed"); ModelState.Remove("IsNewConfirmed"); }
private void DetermineIsDirty(ApplicationOrganisationAdminVM model) { //Compare the Organisation to the original session if (model.OrganisationItem.PublicInstancePropertiesEqual(SessionManager.OrganisationServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private void RepopulateListsFromCacheSession(ApplicationOrganisationAdminVM model) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* model.OrganisationsByTypesList = SessionManager.AllOrganisationsForApplicationByTypesList; model.AllTypesForApplication = SessionManager.AllTypesForApplication; //********************************* //* POPULATE CACHED LISTS * //********************************* // Populate cached lists if they are empty. Will invoke service call }
private void SetAccessContext(ApplicationOrganisationAdminVM model) { //Decide on access context if (null == model.OrganisationItem || model.OrganisationItem.Code == Guid.Empty) { // Create context model.AccessContext = ApplicationOrganisationAccessContext.Create; } else { // Edit context model.AccessContext = ApplicationOrganisationAccessContext.Edit; } }
private ApplicationOrganisationAdminVM ConvertApplicationOrganisationDC(ApplicationOrganisationAdminVMDC returnedObject) { ApplicationOrganisationAdminVM model = new ApplicationOrganisationAdminVM(); // Map Organisation Item model.OrganisationItem = Mapper.Map <OrganisationDC, OrganisationModel>(returnedObject.OrganisationItem); model.ParentOrganisationCode = returnedObject.ParentOrganisation == null ? Guid.Empty : returnedObject.ParentOrganisation.Code; // Map lookup data lists model.MaximumHopsToChildOrganisation = returnedObject.MaximumHopsToChildOrganisation; model.AllTypesForApplication = Mapper.Map <IEnumerable <OrganisationTypeDC>, List <OrganisationTypeModel> >(returnedObject.AllTypesForApplication); model.OrganisationsByTypesList = new List <OrganisationByTypeVM>(); MergeReturnedObjectToModel(model, returnedObject); return(model); }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private ApplicationOrganisationAdminVM GetUpdatedModelOrg() { ApplicationOrganisationAdminVM model = new ApplicationOrganisationAdminVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (SessionManager.CurrentOrganisation != null) { model.OrganisationItem = SessionManager.CurrentOrganisation; } if (SessionManager.RootOrganisation != null) { model.RootNodeOrganisation = SessionManager.RootOrganisation; } model.MaximumHopsToChildOrganisation = SessionManager.MaximumHopsToChildOrganisation; //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (SessionManager.CurrentOrganisation != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.OrganisationItem); //*************************************************************************************************************************** } SetAccessContext(model); SetApplicationOrganisationContext(model); return(model); }
private void ResolveFieldCodesToFieldNamesUsingLists(ApplicationOrganisationAdminVM model) { //TODO: }
public ActionResult Edit() { // Retrieve ID from session string OrganisationCode = SessionManager.OrganisationCode; string ApplicationCode = SessionManager.ApplicationCode; ApplicationOrganisationAdminVM model = new ApplicationOrganisationAdminVM(); // Not from staff or error if (String.IsNullOrEmpty(OrganisationCode)) { //If session has lists then use them //RepopulateListsFromCacheSession(model); // Create service instance AdminServiceClient sc = new AdminServiceClient(); try { // Call service to get Organisation item and any associated lookups ApplicationOrganisationAdminVMDC returnedObject = sc.GetOrganisationWithParent(CurrentUser, CurrentUser, appID, "", Guid.Empty, Guid.Parse(ApplicationCode)); // Close service communication sc.Close(); //Get view model from service model = ConvertApplicationOrganisationDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); AddListsToSession(model); SessionManager.RootOrganisation = model.RootNodeOrganisation; SessionManager.OrganisationServiceVersion = model.OrganisationItem.Clone(); SessionManager.MaximumHopsToChildOrganisation = model.MaximumHopsToChildOrganisation; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, sc); model.Message = message; return(View(model)); } //Assume we are in create mode as no code passed model.OrganisationItem = new OrganisationModel() { IsActive = true }; } //if we have been passed a code then assume we are in edit situation and we need to retrieve from the database. else { // Create service instance AdminServiceClient sc = new AdminServiceClient(); try { // Call service to get Organisation item and any associated lookups ApplicationOrganisationAdminVMDC returnedObject = sc.GetOrganisationWithParent(CurrentUser, CurrentUser, appID, "", Guid.Parse(OrganisationCode), Guid.Parse(ApplicationCode)); // Close service communication sc.Close(); //Get view model from service model = ConvertApplicationOrganisationDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); AddListsToSession(model); //Store the service version SessionManager.RootOrganisation = model.RootNodeOrganisation; SessionManager.OrganisationServiceVersion = model.OrganisationItem.Clone(); SessionManager.MaximumHopsToChildOrganisation = model.MaximumHopsToChildOrganisation; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, sc); model.Message = message; return(View(model)); } } //Adds current retrieved Organisation to session SessionManager.CurrentOrganisation = model.OrganisationItem; SetAccessContext(model); return(View(model)); }