コード例 #1
0
        public async Task <StatusMessage> Delete([FromBody] Guid id)
        {
            try
            {
                await _service.Delete(id);
            }
            catch (ValidationException e)
            {
                // Validation did not succeed
                return(new StatusMessage
                {
                    Type = StatusMessage.Error,
                    Body = e.Message
                });
            }
            catch
            {
                return(new StatusMessage
                {
                    Type = StatusMessage.Error,
                    Body = _localizer.Site["An error occured while deleting the site"]
                });
            }

            return(new StatusMessage
            {
                Type = StatusMessage.Success,
                Body = _localizer.Site["The site was successfully deleted"]
            });
        }
コード例 #2
0
        /// <summary>
        /// Handles the Delete event of the gSites control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSites_Delete(object sender, RowEventArgs e)
        {
            bool canDelete = false;

            var         rockContext = new RockContext();
            SiteService siteService = new SiteService(rockContext);
            Site        site        = siteService.Get(e.RowKeyId);

            if (site != null)
            {
                string errorMessage;
                canDelete = siteService.CanDelete(site, out errorMessage, includeSecondLvl: true);
                if (!canDelete)
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Alert);
                    return;
                }

                siteService.Delete(site);

                rockContext.SaveChanges();

                SiteCache.Flush(site.Id);
            }

            BindGrid();
        }
コード例 #3
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            bool canDelete = false;

            var         rockContext = new RockContext();
            SiteService siteService = new SiteService(rockContext);
            Site        site        = siteService.Get(int.Parse(hfSiteId.Value));

            if (site != null)
            {
                string errorMessage;
                canDelete = siteService.CanDelete(site, out errorMessage, includeSecondLvl: true);
                if (!canDelete)
                {
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Alert);
                    return;
                }

                siteService.Delete(site);

                rockContext.SaveChanges();

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
コード例 #4
0
ファイル: SiteList.ascx.cs プロジェクト: waldo2590/Rock
        /// <summary>
        /// Handles the Delete event of the gSites control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSites_Delete(object sender, RowEventArgs e)
        {
            var              rockContext      = new RockContext();
            SiteService      siteService      = new SiteService(rockContext);
            Site             site             = siteService.Get(e.RowKeyId);
            LayoutService    layoutService    = new LayoutService(rockContext);
            PageService      pageService      = new PageService(rockContext);
            UserLoginService userLoginService = new UserLoginService(rockContext);

            if (site != null)
            {
                var additionalSettings = site.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>() ?? new AdditionalSiteSettings();

                var sitePages = new List <int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                var pageQry = pageService.Queryable("Layout")
                              .Where(t =>
                                     t.Layout.SiteId == site.Id ||
                                     sitePages.Contains(t.Id));

                pageService.DeleteRange(pageQry);

                var layoutQry = layoutService.Queryable()
                                .Where(l =>
                                       l.SiteId == site.Id);
                layoutService.DeleteRange(layoutQry);
                rockContext.SaveChanges(true);

                string errorMessage;
                var    canDelete = siteService.CanDelete(site, out errorMessage, includeSecondLvl: true);
                if (!canDelete)
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Alert);
                    return;
                }

                UserLogin userLogin = null;
                if (additionalSettings.ApiKeyId.HasValue)
                {
                    userLogin = userLoginService.Get(additionalSettings.ApiKeyId.Value);
                }

                rockContext.WrapTransaction(() =>
                {
                    siteService.Delete(site);
                    if (userLogin != null)
                    {
                        userLoginService.Delete(userLogin);
                    }
                    rockContext.SaveChanges();
                });
            }

            BindGrid();
        }
コード例 #5
0
 public async Task <IActionResult> DeleteSite(string siteId)
 {
     if (siteService.Delete(siteId))
     {
         return(Ok());
     }
     return(NotFound());
 }
コード例 #6
0
        public void Delete_ValidId_DataDeleted(int id)
        {
            //act
            var service = new SiteService(_siteRepository.Object, _facilityRepository.Object, _logger.Object);

            service.Delete(id);

            //assert
            Assert.DoesNotContain(_siteData, d => d.Id == id);
        }
コード例 #7
0
ファイル: SiteDetail.ascx.cs プロジェクト: sjison/Rock
        /// <summary>
        /// Handles the Click event of the btnDeleteConfirm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDeleteConfirm_Click(object sender, EventArgs e)
        {
            bool canDelete = false;

            var           rockContext   = new RockContext();
            SiteService   siteService   = new SiteService(rockContext);
            Site          site          = siteService.Get(hfSiteId.Value.AsInteger());
            LayoutService layoutService = new LayoutService(rockContext);
            PageService   pageService   = new PageService(rockContext);

            if (site != null)
            {
                var sitePages = new List <int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                var pageQry = pageService.Queryable("Layout")
                              .Where(t =>
                                     t.Layout.SiteId == site.Id ||
                                     sitePages.Contains(t.Id));

                pageService.DeleteRange(pageQry);

                var layoutQry = layoutService.Queryable()
                                .Where(l =>
                                       l.SiteId == site.Id);
                layoutService.DeleteRange(layoutQry);
                rockContext.SaveChanges(true);

                string errorMessage;
                canDelete = siteService.CanDelete(site, out errorMessage, includeSecondLvl: true);
                if (!canDelete)
                {
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Alert);
                    return;
                }

                siteService.Delete(site);

                rockContext.SaveChanges();

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
コード例 #8
0
        /// <summary>
        /// Handles the Delete event of the gSites control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSites_Delete(object sender, RowEventArgs e)
        {
            SiteService siteService = new SiteService();
            Site        site        = siteService.Get((int)gSites.DataKeys[e.RowIndex]["id"]);

            if (CurrentBlock != null)
            {
                siteService.Delete(site, CurrentPersonId);
                siteService.Save(site, CurrentPersonId);

                SiteCache.Flush(site.Id);
            }

            BindGrid();
        }
コード例 #9
0
        public void Delete_Returns_DeletedSiteInstance()
        {
            //arrange
            var testSite = testSites[0];

            var mockSiteRepo = new Mock <ISiteRepository>();

            mockSiteRepo.Setup(repo => repo.DeleteSite(testSite.Id))
            .Returns(testSite);     //repo returns the "fake deleted" site successfully

            var siteService = new SiteService(mockSiteRepo.Object);

            //act
            var deletedSite = siteService.Delete(testSite.Id);

            //assert
            Assert.NotNull(deletedSite);
            Assert.Equal(testSite.Id, deletedSite.Id);
        }
コード例 #10
0
        /// <summary>
        /// Handles the Delete event of the gSites control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSites_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                SiteService siteService = new SiteService();
                Site site = siteService.Get((int)e.RowKeyValue);
                if (site != null)
                {
                    string errorMessage;
                    if (!siteService.CanDelete(site, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    siteService.Delete(site, CurrentPersonId);
                    siteService.Save(site, CurrentPersonId);

                    SiteCache.Flush(site.Id);
                }
            });

            BindGrid();
        }
コード例 #11
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                SiteService siteService = new SiteService();
                Site site = siteService.Get(int.Parse(hfSiteId.Value));
                if (site != null)
                {
                    string errorMessage;
                    if (!siteService.CanDelete(site, out errorMessage))
                    {
                        mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    siteService.Delete(site, CurrentPersonId);
                    siteService.Save(site, CurrentPersonId);

                    SiteCache.Flush(site.Id);
                }
            });

            NavigateToParentPage();
        }
コード例 #12
0
ファイル: SiteApiController.cs プロジェクト: pyfxl/AALifeWeb
        public async Task <IHttpActionResult> Delete(IEnumerable <SexSpiders> models)
        {
            await service.Delete(models);

            return(Ok());
        }