/// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private IncidentSystemMarkedVM GetUpdatedModel()
        {
            IncidentSystemMarkedVM model = new IncidentSystemMarkedVM();

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

            if (sessionManager.CurrentIncidentSystemMarked != null)
            {
                model.IncidentSystemMarkedItem = sessionManager.CurrentIncidentSystemMarked;
            }

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

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

            SetAccessContext(model);

            return(model);
        }
        private void RepopulateListsFromCacheSession(IncidentSystemMarkedVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            IncidentSystemMarkedLookupListsCacheObject CachedLists = cacheManager.IncidentSystemMarkedListCache;

            // Retrieve any cached lists to model
            model.IncidentList     = CachedLists.IncidentList;
            model.SystemMarkedList = CachedLists.SystemMarkedList;
        }
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = sessionManager.IncidentSystemMarkedCode;

            IncidentSystemMarkedVM model = new IncidentSystemMarkedVM();

            // 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.IncidentSystemMarkedItem = new IncidentSystemMarkedModel();
            }
            //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 IncidentSystemMarked item and any associated lookups
                    IncidentSystemMarkedVMDC returnedObject = sc.GetIncidentSystemMarked(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved IncidentSystemMarked to session
            sessionManager.CurrentIncidentSystemMarked = model.IncidentSystemMarkedItem;
            SetAccessContext(model);

            return(View(model));
        }
        private void SetFlagsFalse(IncidentSystemMarkedVM 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(IncidentSystemMarkedVM model)
 {
     //Compare the IncidentSystemMarked to the original session
     if (model.IncidentSystemMarkedItem.PublicInstancePropertiesEqual(sessionManager.IncidentSystemMarkedServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
        private IncidentSystemMarkedVM ConvertIncidentSystemMarkedDC(IncidentSystemMarkedVMDC returnedObject)
        {
            IncidentSystemMarkedVM model = new IncidentSystemMarkedVM();

            // Map IncidentSystemMarked Item
            model.IncidentSystemMarkedItem = Mapper.Map <IncidentSystemMarkedDC, IncidentSystemMarkedModel>(returnedObject.IncidentSystemMarkedItem);

            // Map lookup data lists
            model.IncidentList     = Mapper.Map <IEnumerable <IncidentDC>, List <IncidentModel> >(returnedObject.IncidentList);
            model.SystemMarkedList = Mapper.Map <IEnumerable <SystemMarkedDC>, List <SystemMarkedModel> >(returnedObject.SystemMarkedList);

            return(model);
        }
 private void SetAccessContext(IncidentSystemMarkedVM model)
 {
     //Decide on access context
     if (null == model.IncidentSystemMarkedItem || model.IncidentSystemMarkedItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = IncidentSystemMarkedAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = IncidentSystemMarkedAccessContext.Edit;
     }
 }
 private void ResolveFieldCodesToFieldNamesUsingLists(IncidentSystemMarkedVM model)
 {
     //TODO:
 }