// // GET: /ApplicationOrganisation/ public ActionResult ApplicationOrganisationSelect() { var model = new ApplicationOrganisationSelectVM(); //Initialize lists model.OrganisationsByTypesList = new List <OrganisationByTypeVM>(); model.ApplicationList = new List <ApplicationModel>(); //Retreive all applications that are available to the current user. //Currently working in ********************GOD MODE********************* - If you have access to this screen you can maintain staff in all apps in the framework. try { var sc = new AdminServiceClient(); var ApplicationList = sc.GetAllApplication(User.Identity.Name, User.Identity.Name, "Framework", "", false); model.ApplicationList = Mapper.Map <IEnumerable <ApplicationDC>, IEnumerable <ApplicationModel> >(ApplicationList).ToList(); } catch (Exception ex) { model.Message = FixedResources.MESSAGE_RETRIEVAL_FAILED; return(View(model)); } //Initialize lists model.OrganisationsByTypesList = new List <OrganisationByTypeVM>(); SessionManager.ApplicationList = model.ApplicationList; SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; return(View(model)); }
private static void MergeReturnedObjectToModel(ApplicationOrganisationSelectVM model, ApplicationOrganisationSelectVMDC 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) { 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++; } } model.RootNodeOrganisation = Mapper.Map <OrganisationModel>(returnedObject.RootNodeOrganisation); model.SelectedApplicationCode = returnedObject.SelectedApplicationCode; //Add the values to session SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList; SessionManager.RootOrganisation = model.RootNodeOrganisation; }
private void RepopulateListsFromCacheSession(ApplicationOrganisationSelectVM model) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* model.ApplicationList = SessionManager.ApplicationList; model.OrganisationsByTypesList = SessionManager.OrganisationByTypeList; //********************************* //* POPULATE CACHED LISTS * //********************************* }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private ApplicationOrganisationSelectVM GetUpdatedModel() { ApplicationOrganisationSelectVM model = new ApplicationOrganisationSelectVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (SessionManager.RootOrganisation != null) { model.RootNodeOrganisation = SessionManager.RootOrganisation; } if (SessionManager.CurrentApplicationCode != null) { model.SelectedApplicationCode = SessionManager.CurrentApplicationCode; } //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 - //************************************************************************************************************************************************************ if (model.OrganisationsByTypesList != null) { 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 WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* return(model); }
private void ResolveFieldCodesToFieldNamesUsingLists(ApplicationOrganisationSelectVM model) { }