Пример #1
0
        public async Task <IActionResult> saveOrganisationLink(LinkAddressToOrganisationViewModel model)
        {
            var user = await GetCurrentUserAsync();

            _organisationProvider.CreateUserAddress_UserOrganisationLink(model.UserAddressID, model.ReturnedIDs, user.Id);
            return(RedirectToAction(nameof(ManageAddresses), new { Message = ManageMessageId.AddOrganisationToEmail }));
        }
Пример #2
0
        public async Task <IActionResult> LinkAddressToOrganisation(Locations loc)
        {
            var user = await GetCurrentUserAsync();

            var userAddress = _addressProvider.getAddressByLocation(user, loc.Id).Id;
            //get all the links for the particular user
            var allLinkedOrganisation = _organisationProvider.getAllLinkedOrganisations(user);
            //get all the links for the particular UserAddress.
            var userAddressOrganisionLinks = _organisationProvider.getAllAddressOrganisationLinks(userAddress);
            //Convert the UserAddress_UserOrganisationLink to List of ApplicationOrganisaion.
            var listOfOrganisationsConnectedToAddress = _organisationProvider.convertUserAddressLinkToApplicationOrganisation(userAddressOrganisionLinks);
            //Find the difference between the two lists.
            List <ApplicationOrganisations> differenceBetweenLists = new List <ApplicationOrganisations>();

            foreach (var org in listOfOrganisationsConnectedToAddress)
            {
                //allLinkedOrganisation will only contain the list of organisation which are not part of the address.
                allLinkedOrganisation.Remove(allLinkedOrganisation.Single(s => s.Id == org.Id));
            }
            //allLinkedOrganisation.Except(listOfOrganisationsConnectedToAddress);
            LinkAddressToOrganisationViewModel model = new LinkAddressToOrganisationViewModel
            {
                UserAddressID = userAddress
            };
            //Create select lists which will be used to render the multiselect listview
            List <SelectListItem> selectListLinkedOrg   = new List <SelectListItem>();
            List <SelectListItem> selectListUnlinkedOrg = new List <SelectListItem>();

            foreach (var c in listOfOrganisationsConnectedToAddress)
            {
                selectListLinkedOrg.Add(new SelectListItem {
                    Text = c.organisationName, Value = c.Id.ToString()
                });
            }
            //foreach (var c in allLinkedOrganisation)
            //{
            //    selectListUnlinkedOrg.Add(new SelectListItem { Text = c.organisationName, Value = c.Id.ToString() });
            //}
            //add the selectListItems to the ModelView
            model.LinkedOrgs           = selectListLinkedOrg;
            model.UnlinkedOrganisation = allLinkedOrganisation;
            //model.UnlinkedOrgs = selectListUnlinkedOrg;
            ViewBag.addressToLinkToOrganisation = loc.ToString();
            return(View("LinkDetailWithOrganisation", model));
        }