Exemplo n.º 1
0
        /// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private SiteStaffVM GetUpdatedModel()
        {
            SiteStaffVM model = new SiteStaffVM();

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

            if (sessionManager.CurrentSiteStaff != null)
            {
                model.SiteStaffItem = sessionManager.CurrentSiteStaff;
            }

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

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

            SetAccessContext(model);

            return(model);
        }
Exemplo n.º 2
0
        private void RepopulateListsFromCacheSession(SiteStaffVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            SiteStaffLookupListsCacheObject CachedLists = cacheManager.SiteStaffListCache;

            // Retrieve any cached lists to model
            model.SiteList  = CachedLists.SiteList;
            model.StaffList = CachedLists.StaffList;
        }
Exemplo n.º 3
0
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = sessionManager.SiteStaffCode;

            SiteStaffVM model = new SiteStaffVM();

            // 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.SiteStaffItem = new SiteStaffModel();
            }
            //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 SiteStaff item and any associated lookups
                    SiteStaffVMDC returnedObject = sc.GetSiteStaff(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved SiteStaff to session
            sessionManager.CurrentSiteStaff = model.SiteStaffItem;
            SetAccessContext(model);

            return(View(model));
        }
Exemplo n.º 4
0
        private void SetFlagsFalse(SiteStaffVM 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");
        }
Exemplo n.º 5
0
 private void DetermineIsDirty(SiteStaffVM model)
 {
     //Compare the SiteStaff to the original session
     if (model.SiteStaffItem.PublicInstancePropertiesEqual(sessionManager.SiteStaffServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
Exemplo n.º 6
0
        private SiteStaffVM ConvertSiteStaffDC(SiteStaffVMDC returnedObject)
        {
            SiteStaffVM model = new SiteStaffVM();

            // Map SiteStaff Item
            model.SiteStaffItem = Mapper.Map <SiteStaffDC, SiteStaffModel>(returnedObject.SiteStaffItem);

            // Map lookup data lists
            model.SiteList  = Mapper.Map <IEnumerable <SiteDC>, List <SiteModel> >(returnedObject.SiteList);
            model.StaffList = Mapper.Map <IEnumerable <StaffDC>, List <StaffModel> >(returnedObject.StaffList);

            return(model);
        }
Exemplo n.º 7
0
 private void SetAccessContext(SiteStaffVM model)
 {
     //Decide on access context
     if (null == model.SiteStaffItem || model.SiteStaffItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = SiteStaffAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = SiteStaffAccessContext.Edit;
     }
 }
Exemplo n.º 8
0
 private void ResolveFieldCodesToFieldNamesUsingLists(SiteStaffVM model)
 {
     //TODO:
 }