public void ApiCreateAttribute(string apiKey, Rock.Core.DTO.Attribute Attribute) { 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add(existingAttribute, user.PersonId); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) { AttributeService.Save(existingAttribute, user.PersonId); } else { throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void CreateAttribute(Rock.Core.DTO.Attribute Attribute) { 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add(existingAttribute, currentUser.PersonId); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) { AttributeService.Save(existingAttribute, currentUser.PersonId); } else { throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } }
public void ApiCreateAttribute( string apiKey, Rock.Core.DTO.Attribute Attribute ) { 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add( existingAttribute, user.PersonId ); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) AttributeService.Save( existingAttribute, user.PersonId ); else throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void CreateAttribute( Rock.Core.DTO.Attribute Attribute ) { 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService(); Rock.Core.Attribute existingAttribute = new Rock.Core.Attribute(); AttributeService.Add( existingAttribute, currentUser.PersonId ); uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute); if (existingAttribute.IsValid) AttributeService.Save( existingAttribute, currentUser.PersonId ); else throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }