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

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

            if (sessionManager.CurrentIncidentLink != null)
            {
                model.IncidentLinkItem = sessionManager.CurrentIncidentLink;
            }

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

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

            SetAccessContext(model);

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

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

            IncidentLinkVM model = new IncidentLinkVM();

            // 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.IncidentLinkItem = new IncidentLinkModel();
            }
            //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 IncidentLink item and any associated lookups
                    IncidentLinkVMDC returnedObject = sc.GetIncidentLink(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved IncidentLink to session
            sessionManager.CurrentIncidentLink = model.IncidentLinkItem;
            SetAccessContext(model);

            return(View(model));
        }
        private void SetFlagsFalse(IncidentLinkVM 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(IncidentLinkVM model)
 {
     //Compare the IncidentLink to the original session
     if (model.IncidentLinkItem.PublicInstancePropertiesEqual(sessionManager.IncidentLinkServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
        private IncidentLinkVM ConvertIncidentLinkDC(IncidentLinkVMDC returnedObject)
        {
            IncidentLinkVM model = new IncidentLinkVM();

            // Map IncidentLink Item
            model.IncidentLinkItem = Mapper.Map <IncidentLinkDC, IncidentLinkModel>(returnedObject.IncidentLinkItem);

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

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