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

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

            if (sessionManager.CurrentLinkedCustomer != null)
            {
                model.LinkedCustomerItem = sessionManager.CurrentLinkedCustomer;
            }

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

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

            SetAccessContext(model);

            return(model);
        }
Esempio n. 2
0
        private void RepopulateListsFromCacheSession(LinkedCustomerVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            LinkedCustomerLookupListsCacheObject CachedLists = cacheManager.LinkedCustomerListCache;

            // Retrieve any cached lists to model
            model.Customer1List = CachedLists.Customer1List;
            model.Customer2List = CachedLists.Customer2List;
        }
Esempio n. 3
0
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = sessionManager.LinkedCustomerCode;

            LinkedCustomerVM model = new LinkedCustomerVM();

            // 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.LinkedCustomerItem = new LinkedCustomerModel();
            }
            //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 LinkedCustomer item and any associated lookups
                    LinkedCustomerVMDC returnedObject = sc.GetLinkedCustomer(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved LinkedCustomer to session
            sessionManager.CurrentLinkedCustomer = model.LinkedCustomerItem;
            SetAccessContext(model);

            return(View(model));
        }
Esempio n. 4
0
        private void SetFlagsFalse(LinkedCustomerVM 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");
        }
Esempio n. 5
0
 private void DetermineIsDirty(LinkedCustomerVM model)
 {
     //Compare the LinkedCustomer to the original session
     if (model.LinkedCustomerItem.PublicInstancePropertiesEqual(sessionManager.LinkedCustomerServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
Esempio n. 6
0
        private LinkedCustomerVM ConvertLinkedCustomerDC(LinkedCustomerVMDC returnedObject)
        {
            LinkedCustomerVM model = new LinkedCustomerVM();

            // Map LinkedCustomer Item
            model.LinkedCustomerItem = Mapper.Map <LinkedCustomerDC, LinkedCustomerModel>(returnedObject.LinkedCustomerItem);

            // Map lookup data lists
            model.Customer1List = Mapper.Map <IEnumerable <CustomerDC>, List <CustomerModel> >(returnedObject.Customer1List);
            model.Customer2List = Mapper.Map <IEnumerable <CustomerDC>, List <CustomerModel> >(returnedObject.Customer2List);

            return(model);
        }
Esempio n. 7
0
 private void SetAccessContext(LinkedCustomerVM model)
 {
     //Decide on access context
     if (null == model.LinkedCustomerItem || model.LinkedCustomerItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = LinkedCustomerAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = LinkedCustomerAccessContext.Edit;
     }
 }
Esempio n. 8
0
 private void ResolveFieldCodesToFieldNamesUsingLists(LinkedCustomerVM model)
 {
     //TODO:
 }