示例#1
0
        public ActionResult DeleteStaffOrganisation(Guid?staffCode, FormCollection form)
        {
            var model = GetUpdatedModel();

            //Set flags false
            SetFlagsFalse(model);

            //Establish which staff organisation to remove
            Guid StaffOrganisationValue = Guid.Empty;

            foreach (string KeyItem in form)
            {
                if (KeyItem.StartsWith("ApplicationStaffAdmin::DeleteStaffOrganisation"))
                {
                    StaffOrganisationValue = Guid.Parse(KeyItem.Substring(47));
                    break;
                }
            }

            var StaffOrganisationItem = model.StaffOrganisationList.Single(x => x.Code == StaffOrganisationValue);

            model.StaffOrganisationList.Remove(StaffOrganisationItem);

            DetermineIsDirty(model);
            return(View(model));
        }
示例#2
0
        public ActionResult UpdateOrganisation(Guid?staffCode, FormCollection form)
        {
            var model = GetUpdatedModel();
            //Set flags false

            //Establish which drop downs need updating
            Guid OrganisationByTypeValue = Guid.Empty;
            Guid PrefixValue             = Guid.Empty;

            foreach (string KeyItem in form)
            {
                if (KeyItem.StartsWith("ApplicationOrganisationSelect::UpdateOrganisation"))
                {
                    PrefixValue = Guid.Parse(KeyItem.Substring(50));
                    var HiddenFieldKey = "OrganisationsByRows[" + PrefixValue.ToString() + "].OrganisationTypeItem.Code";
                    OrganisationByTypeValue = Guid.Parse(form[HiddenFieldKey]);
                    break;
                }
            }

            var AllOrganisationsForApplicationByTypesList = SessionManager.AllOrganisationsForApplicationByTypesList;

            // Modified to handle multiple organisation types for the same level of the organisation hierarchy.
            var clickedItem = model.OrganisationsByTypesList.Single(x => x.OrganisationTypeItem.Code == OrganisationByTypeValue);

            if (clickedItem.SelectedOrganisationCode != null)
            {
                var AllOrgsListsForNextLevel = AllOrganisationsForApplicationByTypesList.FindAll(x => x.OrganisationTypeItem.LevelNumber == clickedItem.OrganisationTypeItem.LevelNumber + 1);
                if (AllOrgsListsForNextLevel != null && AllOrgsListsForNextLevel.Count > 0)
                {
                    OrganisationByTypeVM AllOrgsForNextLevel = null;
                    foreach (OrganisationByTypeVM organisationTypeVMitem in AllOrgsListsForNextLevel)
                    {
                        //int levelNum = organisationTypeVMitem.OrganisationTypeItem.LevelNumber;
                        if (organisationTypeVMitem.OrganisationList.Count > 0)
                        {
                            foreach (var organisationItem in organisationTypeVMitem.OrganisationList)
                            {
                                if (organisationItem.ParentID == Guid.Parse(clickedItem.SelectedOrganisationCode))
                                {
                                    AllOrgsForNextLevel = organisationTypeVMitem;
                                    break;
                                }
                                //var ChildVM = model.OrganisationsByTypesList.SingleOrDefault(x => x.OrganisationTypeItem.ParentOrganisationTypeCode == clickedItem.OrganisationTypeItem.Code);
                            }
                            if (AllOrgsForNextLevel != null)
                            {
                                break;
                            }
                        }
                    }
                    if (AllOrgsForNextLevel != null)
                    {
                        var ChildVMList = model.OrganisationsByTypesList.FindAll(x => x.OrganisationTypeItem.ParentOrganisationTypeCode == clickedItem.OrganisationTypeItem.Code);
                        OrganisationByTypeVM ChildVM = null;
                        if (ChildVMList != null && ChildVMList.Count > 0)
                        {
                            foreach (OrganisationByTypeVM listItem in ChildVMList)
                            {
                                OrganisationByTypeVM ChildVMtemp = null;
                                if (listItem.OrganisationTypeItem.Code == AllOrgsForNextLevel.OrganisationTypeItem.Code)
                                {
                                    ChildVM     = listItem;
                                    ChildVMtemp = listItem;
                                    ChildVM.OrganisationList = AllOrgsForNextLevel.OrganisationList.Where(x => x.ParentID == Guid.Parse(clickedItem.SelectedOrganisationCode)).ToList();
                                }
                                else
                                {
                                    ChildVMtemp = listItem;
                                }
                                //empty the lists below the child of the clicked item
                                var BelowChildVMs = model.OrganisationsByTypesList.Where(x => x.OrganisationTypeItem.LevelNumber >= ChildVMtemp.OrganisationTypeItem.LevelNumber);
                                foreach (var item in BelowChildVMs)
                                {
                                    if (item.OrganisationTypeItem.LevelNumber != ChildVMtemp.OrganisationTypeItem.LevelNumber)
                                    {
                                        item.OrganisationList = new List <OrganisationModel>();
                                    }
                                    else
                                    {
                                        // clear the other lists at the same level i.e. handle multiple organisationTypes with the same parent
                                        if (item.OrganisationList.Count > 0 && Guid.Parse(clickedItem.SelectedOrganisationCode) != item.OrganisationList[0].ParentID)
                                        {
                                            item.OrganisationList = new List <OrganisationModel>();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //Empty the lists below the empty clicked item
                var BelowChildVMs = model.OrganisationsByTypesList.Where(x => x.OrganisationTypeItem.LevelNumber > clickedItem.OrganisationTypeItem.LevelNumber);
                foreach (var item in BelowChildVMs)
                {
                    item.OrganisationList = new List <OrganisationModel>();
                }
            }

            return(View(model));
        }