コード例 #1
0
ファイル: SiteService.cs プロジェクト: webluddite/Rock-ChMS
        public void UpdateSite(string id, Rock.CMS.DTO.Site Site)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.SiteService SiteService  = new Rock.CMS.SiteService();
                Rock.CMS.Site        existingSite = SiteService.Get(int.Parse(id));
                if (existingSite.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingSite).CurrentValues.SetValues(Site);

                    if (existingSite.IsValid)
                    {
                        SiteService.Save(existingSite, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingSite.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Site", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
コード例 #2
0
ファイル: SiteService.cs プロジェクト: webluddite/Rock-ChMS
        public void ApiCreateSite(string apiKey, Rock.CMS.DTO.Site Site)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.SiteService SiteService  = new Rock.CMS.SiteService();
                    Rock.CMS.Site        existingSite = new Rock.CMS.Site();
                    SiteService.Add(existingSite, user.PersonId);
                    uow.objectContext.Entry(existingSite).CurrentValues.SetValues(Site);

                    if (existingSite.IsValid)
                    {
                        SiteService.Save(existingSite, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingSite.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }