Пример #1
0
        /// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private OrganisationVM GetUpdatedModel()
        {
            OrganisationVM model = new OrganisationVM();

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

            if (sessionManager.CurrentOrganisation != null)
            {
                model.OrganisationItem = sessionManager.CurrentOrganisation;
            }

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

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

            SetAccessContext(model);

            return(model);
        }
Пример #2
0
        private void RepopulateListsFromCacheSession(OrganisationVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            OrganisationLookupListsCacheObject CachedLists = cacheManager.OrganisationListCache;

            // Retrieve any cached lists to model
            model.OrganisationTypeList = CachedLists.OrganisationTypeList;
        }
Пример #3
0
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = sessionManager.OrganisationCode;

            OrganisationVM model = new OrganisationVM();

            // 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.OrganisationItem = new OrganisationModel()
                {
                    IsActive = true
                };
            }
            //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 Organisation item and any associated lookups
                    OrganisationVMDC returnedObject = sc.GetOrganisation(CurrentUser, CurrentUser, appID, "", code);

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

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

                    ResolveFieldCodesToFieldNamesUsingLists(model);

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

                    return(View(model));
                }
            }

            //Adds current retrieved Organisation to session
            sessionManager.CurrentOrganisation = model.OrganisationItem;
            SetAccessContext(model);

            return(View(model));
        }
        private void SetFlagsFalse(OrganisationVM model)
        {
            model.IsExitConfirmed = "False";
            model.IsNewConfirmed  = "False";

            //Stop the binder resetting the posted values
            ModelState.Remove("IsDeleteConfirmed");
            ModelState.Remove("IsExitConfirmed");
            ModelState.Remove("IsNewConfirmed");
        }
Пример #5
0
 private void DetermineIsDirty(OrganisationVM model)
 {
     //Compare the Organisation to the original session
     if (model.OrganisationItem.PublicInstancePropertiesEqual(sessionManager.OrganisationServiceVersion, "RowIdentifier"))
     {
         model.IsViewDirty = false;
     }
     else
     {
         model.IsViewDirty = true;
     }
 }
Пример #6
0
        private OrganisationVM ConvertOrganisationDC(OrganisationVMDC returnedObject)
        {
            OrganisationVM model = new OrganisationVM();

            // Map Organisation Item
            model.OrganisationItem = Mapper.Map <OrganisationDC, OrganisationModel>(returnedObject.OrganisationItem);

            // Map lookup data lists
            model.OrganisationTypeList = Mapper.Map <IEnumerable <OrganisationTypeDC>, List <OrganisationTypeModel> >(returnedObject.OrganisationTypeList);

            return(model);
        }
Пример #7
0
 private void SetAccessContext(OrganisationVM model)
 {
     //Decide on access context
     if (null == model.OrganisationItem || model.OrganisationItem.Code == Guid.Empty)
     {
         // Create context
         model.AccessContext = OrganisationAccessContext.Create;
     }
     else
     {
         // Edit context
         model.AccessContext = OrganisationAccessContext.Edit;
     }
 }
Пример #8
0
        public async Task <IActionResult> CreateOrganisation([FromBody] OrganisationVM organisation)
        {
            var organisationDto = new OrganisationDto
            {
                Active      = true,
                Address     = organisation.Address,
                Comments    = organisation.Comments,
                Description = organisation.Description,
                Email       = organisation.Email,
                Name        = organisation.Name,
                Phone       = organisation.Phone
            };
            await _orgService.CreateOrganisation(organisationDto);

            return(Ok(new { status = true, data = string.Empty, message = "organisation account created." }));
        }
Пример #9
0
 private void ResolveFieldCodesToFieldNamesUsingLists(OrganisationVM model)
 {
     //TODO:
 }