private void RepopulateListsFromCacheSession(LastUpdateVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            LastUpdateLookupListsCacheObject CachedLists = CacheManager.LastUpdateListCache;

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

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

            if (SessionManager.CurrentLastUpdate != null)
            {
                model.LastUpdateItem = SessionManager.CurrentLastUpdate;
            }

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

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

            SetAccessContext(model);

            return(model);
        }
        private LastUpdateVM ConvertLastUpdateDC(LastUpdateVMDC returnedObject)
        {
            LastUpdateVM model = new LastUpdateVM();

            // Map LastUpdate Item
            model.LastUpdateItem = Mapper.Map <LastUpdateDC, LastUpdateModel>(returnedObject.LastUpdateItem);

            // Map lookup data lists

            return(model);
        }
        private void SetFlagsFalse(LastUpdateVM 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.LastUpdateCode;

            LastUpdateVM model = new LastUpdateVM();

            // 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.LastUpdateItem = new LastUpdateModel();
            }
            //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 LastUpdate item and any associated lookups
                    LastUpdateVMDC returnedObject = sc.GetLastUpdate(CurrentUser, CurrentUser, appID, "", code);

                    // Close service communication
                    sc.Close();

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    //Store the service version
                    SessionManager.LastUpdateServiceVersion = model.LastUpdateItem;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            //Adds current retrieved LastUpdate to session
            SessionManager.CurrentLastUpdate = model.LastUpdateItem;
            SetAccessContext(model);

            return(View(model));
        }
 private void DetermineIsDirty(LastUpdateVM model)
 {
     //Compare the LastUpdate to the original session
     if (model.LastUpdateItem.PublicInstancePropertiesEqual(SessionManager.LastUpdateServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
 private void SetAccessContext(LastUpdateVM model)
 {
     //Decide on access context
     if (null == model.LastUpdateItem || model.LastUpdateItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = LastUpdateAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = LastUpdateAccessContext.Edit;
     }
 }
 private void ResolveFieldCodesToFieldNamesUsingLists(LastUpdateVM model)
 {
     //TODO:
 }