コード例 #1
0
        public ActionResult UpdateApplication(Guid?staffCode, FormCollection form)
        {
            // Get the updated model
            var model = GetUpdatedModel();

            if (model.SelectedApplicationCode.HasValue)
            {
                // Create instance of Admin service
                AdminServiceClient sc = new AdminServiceClient();

                try
                {
                    ApplicationOrganisationSelectVMDC returnedObject = sc.GetApplicationOrganisationsByApplicationCode(User.Identity.Name, User.Identity.Name, "Framework", "", model.SelectedApplicationCode.Value);
                    model.OrganisationsByTypesList = new List <OrganisationByTypeVM>();
                    //Merge the returned DC to the model
                    MergeReturnedObjectToModel(model, returnedObject);
                }
                catch (Exception e)
                {
                    // Handle exception
                    ExceptionManager.HandleException(e, sc);

                    return(null);
                }
            }
            else
            {
                //remove the current values from session
                SessionManager.OrganisationByTypeList = null;
                //remove the current values from session
                model.OrganisationsByTypesList = null;
                // Redirect to Admin screen of item selected
                return(RedirectToAction("ApplicationOrganisationSelect", "ApplicationOrganisation"));
            }
            ModelState.Clear();
            return(View(model));
        }
コード例 #2
0
        private static void MergeReturnedObjectToModel(ApplicationOrganisationSelectVM model, ApplicationOrganisationSelectVMDC returnedObject)
        {
            //Clear the organisations list and repopulate from the returned object
            model.OrganisationsByTypesList.Clear();
            List <OrganisationByTypeVM> AllOrganisationsForApplicationByTypesList = new List <OrganisationByTypeVM>();

            foreach (var item in returnedObject.OrganisationsByTypesList)
            {
                AllOrganisationsForApplicationByTypesList.Add(new OrganisationByTypeVM()
                {
                    OrganisationList     = Mapper.Map <IEnumerable <OrganisationDC>, IEnumerable <OrganisationModel> >(item.OrganisationList).ToList(),
                    OrganisationTypeItem = Mapper.Map <OrganisationTypeModel>(item.OrganisationTypeItem)
                });
            }

            SessionManager.AllOrganisationsForApplicationByTypesList = AllOrganisationsForApplicationByTypesList;

            //initialise the available orgs, the first drop down should have THE ROOT ORGANISATION selected
            if (AllOrganisationsForApplicationByTypesList.Count > 1)
            {
                int i = 0;
                foreach (var item in AllOrganisationsForApplicationByTypesList)
                {
                    if (i == 0)
                    {
                        model.OrganisationsByTypesList.Add(new OrganisationByTypeVM()
                        {
                            OrganisationList         = item.OrganisationList,
                            OrganisationTypeItem     = item.OrganisationTypeItem,
                            SelectedOrganisationCode = item.OrganisationList[0].Code.ToString()
                        });
                    }
                    else
                    {
                        model.OrganisationsByTypesList.Add(new OrganisationByTypeVM()
                        {
                            OrganisationList         = !string.IsNullOrEmpty(model.OrganisationsByTypesList[i - 1].SelectedOrganisationCode) ? item.OrganisationList.Where(x => x.ParentID == Guid.Parse(model.OrganisationsByTypesList[i - 1].SelectedOrganisationCode)).ToList() : new List <OrganisationModel>(),
                            OrganisationTypeItem     = item.OrganisationTypeItem,
                            SelectedOrganisationCode = ""
                        });
                    }
                    i++;
                }
            }


            model.RootNodeOrganisation = Mapper.Map <OrganisationModel>(returnedObject.RootNodeOrganisation);

            model.SelectedApplicationCode = returnedObject.SelectedApplicationCode;

            //Add the values to session
            SessionManager.OrganisationByTypeList = model.OrganisationsByTypesList;

            SessionManager.RootOrganisation = model.RootNodeOrganisation;
        }