private void RepopulateListsFromCacheSession(CommandsVM model) { // Populate cached lists if they are empty. Will invoke service call CommandsLookupListsCacheObject CachedLists = CacheManager.CommandsListCache; // Retrieve any cached lists to model }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private CommandsVM GetUpdatedModel() { CommandsVM model = new CommandsVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (SessionManager.CurrentCommands != null) { model.CommandsItem = SessionManager.CurrentCommands; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (SessionManager.CurrentCommands != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.CommandsItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
private CommandsVM ConvertCommandsDC(CommandsVMDC returnedObject) { CommandsVM model = new CommandsVM(); // Map Commands Item model.CommandsItem = Mapper.Map <CommandsDC, CommandsModel>(returnedObject.CommandsItem); // Map lookup data lists return(model); }
private void SetFlagsFalse(CommandsVM 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"); }
public ActionResult Edit() { // Retrieve ID from session string code = SessionManager.CommandsCode; CommandsVM model = new CommandsVM(); // 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.CommandsItem = new CommandsModel(); } //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 Commands item and any associated lookups CommandsVMDC returnedObject = sc.GetCommands(CurrentUser, CurrentUser, appID, "", code); // Close service communication sc.Close(); //Get view model from service model = ConvertCommandsDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version SessionManager.CommandsServiceVersion = model.CommandsItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, sc); model.Message = message; return(View(model)); } } //Adds current retrieved Commands to session SessionManager.CurrentCommands = model.CommandsItem; SetAccessContext(model); return(View(model)); }
private void DetermineIsDirty(CommandsVM model) { //Compare the Commands to the original session if (model.CommandsItem.PublicInstancePropertiesEqual(SessionManager.CommandsServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private void SetAccessContext(CommandsVM model) { //Decide on access context if (null == model.CommandsItem || model.CommandsItem.Code == Guid.Empty) { // Create context model.AccessContext = CommandsAccessContext.Create; } else { // Edit context model.AccessContext = CommandsAccessContext.Edit; } }
private void ResolveFieldCodesToFieldNamesUsingLists(CommandsVM model) { //TODO: }