private void RepopulateListsFromCacheSession(ControlMeasureVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            ControlMeasureLookupListsCacheObject CachedLists = cacheManager.ControlMeasureListCache;

            // Retrieve any cached lists to model
        }
        /// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private ControlMeasureVM GetUpdatedModel()
        {
            ControlMeasureVM model = new ControlMeasureVM();

            RepopulateListsFromCacheSession(model);
            model.Message = "";

            if (sessionManager.CurrentControlMeasure != null)
            {
                model.ControlMeasureItem = sessionManager.CurrentControlMeasure;
            }

            //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING **************************
            bool result = TryUpdateModel(model);//This also validates and sets ModelState

            //*******************************************************************************************************************************
            if (sessionManager.CurrentControlMeasure != null)
            {
                //*****************************************PREVENT OVER POSTING ATTACKS******************************************************
                //Get the values for read only fields from session
                MergeNewValuesWithOriginal(model.ControlMeasureItem);
                //***************************************************************************************************************************
            }

            SetAccessContext(model);

            return(model);
        }
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = sessionManager.ControlMeasureCode;

            ControlMeasureVM model = new ControlMeasureVM();

            // 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.ControlMeasureItem = new ControlMeasureModel()
                {
                    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 ControlMeasure item and any associated lookups
                    ControlMeasureVMDC returnedObject = sc.GetControlMeasure(CurrentUser, CurrentUser, appID, "", code);

                    // Close service communication
                    ((ICommunicationObject)sc).Close();

                    //Get view model from service
                    model = ConvertControlMeasureDC(returnedObject);

                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    //Store the service version
                    sessionManager.ControlMeasureServiceVersion = model.ControlMeasureItem;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            //Adds current retrieved ControlMeasure to session
            sessionManager.CurrentControlMeasure = model.ControlMeasureItem;
            SetAccessContext(model);

            return(View(model));
        }
        private ControlMeasureVM ConvertControlMeasureDC(ControlMeasureVMDC returnedObject)
        {
            ControlMeasureVM model = new ControlMeasureVM();

            // Map ControlMeasure Item
            model.ControlMeasureItem = Mapper.Map <ControlMeasureDC, ControlMeasureModel>(returnedObject.ControlMeasureItem);

            // Map lookup data lists

            return(model);
        }
        private void SetFlagsFalse(ControlMeasureVM 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(ControlMeasureVM model)
 {
     //Compare the ControlMeasure to the original session
     if (model.ControlMeasureItem.PublicInstancePropertiesEqual(sessionManager.ControlMeasureServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
 private void SetAccessContext(ControlMeasureVM model)
 {
     //Decide on access context
     if (null == model.ControlMeasureItem || model.ControlMeasureItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = ControlMeasureAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = ControlMeasureAccessContext.Edit;
     }
 }
 private void ResolveFieldCodesToFieldNamesUsingLists(ControlMeasureVM model)
 {
     //TODO:
 }