예제 #1
0
        private StaffApplicationAdminVM ConvertSecurityCheckDC(StaffApplicationAdminVMDC returnedObject)
        {
            StaffApplicationAdminVM model = new StaffApplicationAdminVM();

            RepopulateListsFromCacheSession(model);

            return(model);
        }
예제 #2
0
        private static void MergeReturnedObjectToModel(StaffApplicationAdminVM model, StaffApplicationAdminVMDC returnedObject)
        {
            model.StaffItem = Mapper.Map <StaffModel>(returnedObject.StaffItem);
            SessionManager.CurrentStaffForAdmin = model.StaffItem;
            //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++;
                }
            }

            //RoleList comes from the other service so don't merge it!!!!!!!!!!!!!!!!!!
            //model.RoleList = returnedObject.RoleList.ToList();

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

            model.SelectedApplicationCode = returnedObject.SelectedApplicationCode;

            //Clear the staff application attribute list and repopulate from the returned object
            model.StaffApplicationAttributeList.Clear();
            foreach (var item in returnedObject.StaffApplicationAttributeList)
            {
                model.StaffApplicationAttributeList.Add(new StaffApplicationAttributeVM()
                {
                    ApplicationAttributeItem = Mapper.Map <ApplicationAttributeModel>(item.ApplicationAttributeItem),
                    StaffAttributeItem       = Mapper.Map <StaffAttributesModel>(item.StaffAttributeItem)
                });
            }


            model.StaffOrganisationList = Mapper.Map <IEnumerable <StaffOrganisationDC>, IEnumerable <StaffOrganisationModel> >(returnedObject.StaffOrganisationList).ToList();

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

            List <StaffApplicationAttributeVM> SortedList = model.StaffApplicationAttributeList.OrderBy(x => x.ApplicationAttributeItem.AttributeName).ToList();

            model.StaffApplicationAttributeList          = SortedList;
            SessionManager.StaffApplicationAttributeList = model.StaffApplicationAttributeList;

            //Need to clone the staff attribute lists
            var AttributeDBList = new List <StaffApplicationAttributeVM>();

            foreach (StaffApplicationAttributeVM item in model.StaffApplicationAttributeList)
            {
                AttributeDBList.Add(new StaffApplicationAttributeVM()
                {
                    StaffAttributeItem       = item.StaffAttributeItem.Clone(),
                    ApplicationAttributeItem = item.ApplicationAttributeItem
                });
            }
            SessionManager.StaffApplicationAttributeListDBVersion = AttributeDBList;


            SessionManager.StaffOrganisationList = model.StaffOrganisationList;

            //Need to clone all the items in the list and store them away as the current db version of the list
            var DBList = new List <StaffOrganisationModel>();

            foreach (StaffOrganisationModel item in model.StaffOrganisationList)
            {
                DBList.Add(item.Clone());
            }
            SessionManager.StaffOrganisationListDBVersion = DBList;
            SessionManager.StaffRoleList    = model.RoleList;
            SessionManager.RootOrganisation = model.RootNodeOrganisation;
        }
예제 #3
0
        public ActionResult UpdateApplication(Guid?staffCode, FormCollection form)
        {
            // Get the updated model
            var model = GetUpdatedModel();

            //Set flags false
            SetFlagsFalse(model);

            // Create instance of Authorisation service
            var authSc = new AuthorisationServiceClient();

            try
            {
                List <string> roleList = authSc.GetUserRoles(CurrentUser, CurrentUser, appID, "", model.StaffItem.Code.ToString(), model.SelectedApplicationCode).ToList();
                model.RoleList = roleList;
            }
            catch (Exception e)
            {
                // Handle exception
                if (e.Message == "Failed to find User ID in Active Directory")
                {
                    model.Message = e.Message;
                    // ModelState.AddModelError("SelectedApplicationCode", string.Format("Failed to find User ID in Active Directory"));
                }
                ExceptionManager.HandleException(e, authSc);
                //return null;
            }

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

                try
                {
                    StaffApplicationAdminVMDC returnedObject = sc.GetStaffApplicationAdministrationByStaffCodeAndApplicationCode(User.Identity.Name, User.Identity.Name, "Framework", "", model.SelectedApplicationCode.Value, model.StaffItem.Code);

                    //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;
                SessionManager.StaffApplicationAttributeList = null;
                SessionManager.StaffOrganisationList         = null;
                //remove the current values from session
                model.OrganisationsByTypesList      = null;
                model.StaffApplicationAttributeList = null;
                model.StaffOrganisationList         = null;
                return(RedirectToAction("ApplicationStaffAdmin", "Admin"));
                // /Admin/ApplicationStaffAdmin
            }

            DetermineIsDirty(model);
            ModelState.Clear();
            return(View(model));
        }