private void RepopulateListsFromCacheSession(AbuseTypeVM model) { // Populate cached lists if they are empty. Will invoke service call AbuseTypeLookupListsCacheObject CachedLists = cacheManager.AbuseTypeListCache; // Retrieve any cached lists to model }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private AbuseTypeVM GetUpdatedModel() { AbuseTypeVM model = new AbuseTypeVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (sessionManager.CurrentAbuseType != null) { model.AbuseTypeItem = sessionManager.CurrentAbuseType; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (sessionManager.CurrentAbuseType != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.AbuseTypeItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.AbuseTypeCode; AbuseTypeVM model = new AbuseTypeVM(); // 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.AbuseTypeItem = new AbuseTypeModel() { 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 AbuseType item and any associated lookups AbuseTypeVMDC returnedObject = sc.GetAbuseType(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertAbuseTypeDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.AbuseTypeServiceVersion = model.AbuseTypeItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved AbuseType to session sessionManager.CurrentAbuseType = model.AbuseTypeItem; SetAccessContext(model); return(View(model)); }
private AbuseTypeVM ConvertAbuseTypeDC(AbuseTypeVMDC returnedObject) { AbuseTypeVM model = new AbuseTypeVM(); // Map AbuseType Item model.AbuseTypeItem = Mapper.Map <AbuseTypeDC, AbuseTypeModel>(returnedObject.AbuseTypeItem); // Map lookup data lists return(model); }
private void SetFlagsFalse(AbuseTypeVM model) { model.IsDeleteConfirmed = "False"; 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(AbuseTypeVM model) { //Compare the AbuseType to the original session if (model.AbuseTypeItem.PublicInstancePropertiesEqual(sessionManager.AbuseTypeServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private void SetAccessContext(AbuseTypeVM model) { //Decide on access context if (null == model.AbuseTypeItem || model.AbuseTypeItem.Code == Guid.Empty) { // Create context model.AccessContext = AbuseTypeAccessContext.Create; } else { // Edit context model.AccessContext = AbuseTypeAccessContext.Edit; } }
private void ResolveFieldCodesToFieldNamesUsingLists(AbuseTypeVM model) { //TODO: }