/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private AttachmentDataVM GetUpdatedModel() { AttachmentDataVM model = new AttachmentDataVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (sessionManager.CurrentAttachmentData != null) { model.AttachmentDataItem = sessionManager.CurrentAttachmentData; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (sessionManager.CurrentAttachmentData != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.AttachmentDataItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
private void RepopulateListsFromCacheSession(AttachmentDataVM model) { // Populate cached lists if they are empty. Will invoke service call AttachmentDataLookupListsCacheObject CachedLists = cacheManager.AttachmentDataListCache; // Retrieve any cached lists to model model.AttachmentList = CachedLists.AttachmentList; }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.AttachmentDataCode; AttachmentDataVM model = new AttachmentDataVM(); // 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.AttachmentDataItem = new AttachmentDataModel(); } //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 AttachmentData item and any associated lookups AttachmentDataVMDC returnedObject = sc.GetAttachmentData(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertAttachmentDataDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.AttachmentDataServiceVersion = model.AttachmentDataItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved AttachmentData to session sessionManager.CurrentAttachmentData = model.AttachmentDataItem; SetAccessContext(model); return(View(model)); }
private void SetFlagsFalse(AttachmentDataVM 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(AttachmentDataVM model) { //Compare the AttachmentData to the original session if (model.AttachmentDataItem.PublicInstancePropertiesEqual(sessionManager.AttachmentDataServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private AttachmentDataVM ConvertAttachmentDataDC(AttachmentDataVMDC returnedObject) { AttachmentDataVM model = new AttachmentDataVM(); // Map AttachmentData Item model.AttachmentDataItem = Mapper.Map <AttachmentDataDC, AttachmentDataModel>(returnedObject.AttachmentDataItem); // Map lookup data lists model.AttachmentList = Mapper.Map <IEnumerable <AttachmentDC>, List <AttachmentModel> >(returnedObject.AttachmentList); return(model); }
private void SetAccessContext(AttachmentDataVM model) { //Decide on access context if (null == model.AttachmentDataItem || model.AttachmentDataItem.Code == Guid.Empty) { // Create context model.AccessContext = AttachmentDataAccessContext.Create; } else { // Edit context model.AccessContext = AttachmentDataAccessContext.Edit; } }
private void ResolveFieldCodesToFieldNamesUsingLists(AttachmentDataVM model) { //TODO: }