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

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

            if (sessionManager.CurrentIncidentUpdateEvent != null)
            {
                model.IncidentUpdateEventItem = sessionManager.CurrentIncidentUpdateEvent;
            }

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

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

            SetAccessContext(model);

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

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

            IncidentUpdateEventVM model = new IncidentUpdateEventVM();

            // 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.IncidentUpdateEventItem = new IncidentUpdateEventModel();
            }
            //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 IncidentUpdateEvent item and any associated lookups
                    IncidentUpdateEventVMDC returnedObject = sc.GetIncidentUpdateEvent(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved IncidentUpdateEvent to session
            sessionManager.CurrentIncidentUpdateEvent = model.IncidentUpdateEventItem;
            SetAccessContext(model);

            return(View(model));
        }
        private void SetFlagsFalse(IncidentUpdateEventVM 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(IncidentUpdateEventVM model)
 {
     //Compare the IncidentUpdateEvent to the original session
     if (model.IncidentUpdateEventItem.PublicInstancePropertiesEqual(sessionManager.IncidentUpdateEventServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
        private IncidentUpdateEventVM ConvertIncidentUpdateEventDC(IncidentUpdateEventVMDC returnedObject)
        {
            IncidentUpdateEventVM model = new IncidentUpdateEventVM();

            // Map IncidentUpdateEvent Item
            model.IncidentUpdateEventItem = Mapper.Map <IncidentUpdateEventDC, IncidentUpdateEventModel>(returnedObject.IncidentUpdateEventItem);

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

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