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

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

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

            if (sessionManager.CurrentContingencyArrangement != null)
            {
                model.ContingencyArrangementItem = sessionManager.CurrentContingencyArrangement;
            }

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

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

            SetAccessContext(model);

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

            ContingencyArrangementVM model = new ContingencyArrangementVM();

            // 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.ContingencyArrangementItem = new ContingencyArrangementModel()
                {
                    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 ContingencyArrangement item and any associated lookups
                    ContingencyArrangementVMDC returnedObject = sc.GetContingencyArrangement(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved ContingencyArrangement to session
            sessionManager.CurrentContingencyArrangement = model.ContingencyArrangementItem;
            SetAccessContext(model);

            return(View(model));
        }
        private ContingencyArrangementVM ConvertContingencyArrangementDC(ContingencyArrangementVMDC returnedObject)
        {
            ContingencyArrangementVM model = new ContingencyArrangementVM();

            // Map ContingencyArrangement Item
            model.ContingencyArrangementItem = Mapper.Map <ContingencyArrangementDC, ContingencyArrangementModel>(returnedObject.ContingencyArrangementItem);

            // Map lookup data lists

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