Esempio n. 1
0
        protected async Task <SiteCollectionMapViewModel> GetSiteCollectionListAsync(string clientId, string siteId)
        {
            var availableSiteCollections = await _siteCollectionManager.GetSiteCollectionsAsync(clientId);

            var assignedSiteCollections = await _siteManager.GetSiteCollectionsAsync(siteId);

            var siteCollectionMap = new SiteCollectionMapViewModel()
            {
                SiteId   = siteId,
                ClientId = clientId
            };

            foreach (var item in availableSiteCollections)
            {
                var newItem = new SiteCollectionMapViewModel.Item();
                newItem.Id   = item.Id;
                newItem.Name = item.Name;
                if (assignedSiteCollections.Where(x => x.Id == item.Id).Any())
                {
                    newItem.Selected       = true;
                    newItem.OriginalStatus = true;
                }
                else
                {
                    newItem.Selected       = false;
                    newItem.OriginalStatus = false;
                }
                siteCollectionMap.Items.Add(newItem);
            }
            return(siteCollectionMap);
        }
Esempio n. 2
0
        public async Task <ActionResult> SaveSiteCollections(SiteCollectionMapViewModel model)
        {
            if (model != null)
            {
                var removeIds = model.Items.Where(m => (m.Selected == false) && (m.OriginalStatus != m.Selected)).Select(i => i.Id).ToList();
                await _siteManager.RemoveSiteCollectionsAsync(model.SiteId, removeIds);

                var addIds = model.Items.Where(m => (m.Selected == true) && (m.OriginalStatus != m.Selected)).Select(i => i.Id).ToList();
                await _siteManager.AddSiteCollectionsAsync(model.SiteId, addIds);

                return(Ok(model));
            }
            return(BadRequest(ModelState));
        }