/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private OrganisationTypeVM GetUpdatedModel() { OrganisationTypeVM model = new OrganisationTypeVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (sessionManager.CurrentOrganisationType != null) { model.OrganisationTypeItem = sessionManager.CurrentOrganisationType; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (sessionManager.CurrentOrganisationType != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.OrganisationTypeItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.OrganisationTypeCode; OrganisationTypeVM model = new OrganisationTypeVM(); // Not from staff or error if (String.IsNullOrEmpty(code)) { //If session has lists then use them RepopulateListsFromCacheSession(model); //Assume we are in create mode as no code passed model.OrganisationTypeItem = new OrganisationTypeModel() { 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 IUcbService sc = UcbService; try { // Call service to get OrganisationType item and any associated lookups OrganisationTypeVMDC returnedObject = sc.GetOrganisationType(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertOrganisationTypeDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.OrganisationTypeServiceVersion = model.OrganisationTypeItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved OrganisationType to session sessionManager.CurrentOrganisationType = model.OrganisationTypeItem; SetAccessContext(model); return(View(model)); }
private void RepopulateListsFromCacheSession(OrganisationTypeVM model) { // Populate cached lists if they are empty. Will invoke service call OrganisationTypeLookupListsCacheObject CachedLists = cacheManager.OrganisationTypeListCache; // Retrieve any cached lists to model model.OrganisationTypeGroupList = CachedLists.OrganisationTypeGroupList; model.ParentOrganisationTypeList = CachedLists.ParentOrganisationTypeList; }
private void SetFlagsFalse(OrganisationTypeVM 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(OrganisationTypeVM model) { //Compare the OrganisationType to the original session if (model.OrganisationTypeItem.PublicInstancePropertiesEqual(sessionManager.OrganisationTypeServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private OrganisationTypeVM ConvertOrganisationTypeDC(OrganisationTypeVMDC returnedObject) { OrganisationTypeVM model = new OrganisationTypeVM(); // Map OrganisationType Item model.OrganisationTypeItem = Mapper.Map <OrganisationTypeDC, OrganisationTypeModel>(returnedObject.OrganisationTypeItem); // Map lookup data lists model.OrganisationTypeGroupList = Mapper.Map <IEnumerable <OrganisationTypeGroupDC>, List <OrganisationTypeGroupModel> >(returnedObject.OrganisationTypeGroupList); model.ParentOrganisationTypeList = Mapper.Map <IEnumerable <OrganisationTypeDC>, List <OrganisationTypeModel> >(returnedObject.ParentOrganisationTypeList); return(model); }
private void SetAccessContext(OrganisationTypeVM model) { //Decide on access context if (null == model.OrganisationTypeItem || model.OrganisationTypeItem.Code == Guid.Empty) { // Create context model.AccessContext = OrganisationTypeAccessContext.Create; } else { // Edit context model.AccessContext = OrganisationTypeAccessContext.Edit; } }
private void ResolveFieldCodesToFieldNamesUsingLists(OrganisationTypeVM model) { //TODO: }