/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private CustomerControlMeasureVM GetUpdatedModel() { CustomerControlMeasureVM model = new CustomerControlMeasureVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (sessionManager.CurrentCustomerControlMeasure != null) { model.CustomerControlMeasureItem = sessionManager.CurrentCustomerControlMeasure; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (sessionManager.CurrentCustomerControlMeasure != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.CustomerControlMeasureItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
private void RepopulateListsFromCacheSession(CustomerControlMeasureVM model) { // Populate cached lists if they are empty. Will invoke service call CustomerControlMeasureLookupListsCacheObject CachedLists = cacheManager.CustomerControlMeasureListCache; // Retrieve any cached lists to model model.CustomerList = CachedLists.CustomerList; model.ControlMeasureList = CachedLists.ControlMeasureList; }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.CustomerControlMeasureCode; CustomerControlMeasureVM model = new CustomerControlMeasureVM(); // 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.CustomerControlMeasureItem = new CustomerControlMeasureModel(); } //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 CustomerControlMeasure item and any associated lookups CustomerControlMeasureVMDC returnedObject = sc.GetCustomerControlMeasure(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertCustomerControlMeasureDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.CustomerControlMeasureServiceVersion = model.CustomerControlMeasureItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved CustomerControlMeasure to session sessionManager.CurrentCustomerControlMeasure = model.CustomerControlMeasureItem; SetAccessContext(model); return(View(model)); }
private void SetFlagsFalse(CustomerControlMeasureVM 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(CustomerControlMeasureVM model) { //Compare the CustomerControlMeasure to the original session if (model.CustomerControlMeasureItem.PublicInstancePropertiesEqual(sessionManager.CustomerControlMeasureServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private CustomerControlMeasureVM ConvertCustomerControlMeasureDC(CustomerControlMeasureVMDC returnedObject) { CustomerControlMeasureVM model = new CustomerControlMeasureVM(); // Map CustomerControlMeasure Item model.CustomerControlMeasureItem = Mapper.Map <CustomerControlMeasureDC, CustomerControlMeasureModel>(returnedObject.CustomerControlMeasureItem); // Map lookup data lists model.CustomerList = Mapper.Map <IEnumerable <CustomerDC>, List <CustomerModel> >(returnedObject.CustomerList); model.ControlMeasureList = Mapper.Map <IEnumerable <ControlMeasureDC>, List <ControlMeasureModel> >(returnedObject.ControlMeasureList); return(model); }
private void SetAccessContext(CustomerControlMeasureVM model) { //Decide on access context if (null == model.CustomerControlMeasureItem || model.CustomerControlMeasureItem.Code == Guid.Empty) { // Create context model.AccessContext = CustomerControlMeasureAccessContext.Create; } else { // Edit context model.AccessContext = CustomerControlMeasureAccessContext.Edit; } }
private void ResolveFieldCodesToFieldNamesUsingLists(CustomerControlMeasureVM model) { //TODO: }