public void UpdateAttributeValue(string id, Rock.Core.DTO.AttributeValue AttributeValue) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue existingAttributeValue = AttributeValueService.Get(int.Parse(id)); if (existingAttributeValue.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue); if (existingAttributeValue.IsValid) { AttributeValueService.Save(existingAttributeValue, currentUser.PersonId); } else { throw new WebFaultException <string>(existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateAttributeValue(string apiKey, Rock.Core.DTO.AttributeValue AttributeValue) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue existingAttributeValue = new Rock.Core.AttributeValue(); AttributeValueService.Add(existingAttributeValue, user.PersonId); uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue); if (existingAttributeValue.IsValid) { AttributeValueService.Save(existingAttributeValue, user.PersonId); } else { throw new WebFaultException <string>(existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.Core.DTO.AttributeValue ApiGet(string id, string apiKey) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get(int.Parse(id)); if (AttributeValue.Authorized("View", user)) { return(AttributeValue.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this AttributeValue", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteAttributeValue(string id) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get(int.Parse(id)); if (AttributeValue.Authorized("Edit", currentUser)) { AttributeValueService.Delete(AttributeValue, currentUser.PersonId); AttributeValueService.Save(AttributeValue, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden); } } }
/// <summary> /// Saves an attribute value. /// </summary> /// <param name="model">The model.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> /// <param name="personId">The person id.</param> public static void SaveAttributeValue(IHasAttributes model, Rock.Web.Cache.Attribute attribute, string newValue, int?personId) { Core.AttributeValueService attributeValueService = new Core.AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, model.Id).FirstOrDefault(); if (attributeValue == null) { attributeValue = new Rock.Core.AttributeValue(); attributeValue.AttributeId = attribute.Id; attributeValue.EntityId = model.Id; attributeValue.Order = 0; attributeValueService.Add(attributeValue, personId); } attributeValue.Value = newValue; attributeValueService.Save(attributeValue, personId); model.AttributeValues[attribute.Key] = new KeyValuePair <string, List <Rock.Core.DTO.AttributeValue> >( attribute.Name, new List <Rock.Core.DTO.AttributeValue>() { attributeValue.DataTransferObject }); }
/// <summary> /// Saves an attribute value. /// </summary> /// <param name="model">The model.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> /// <param name="personId">The person id.</param> public static void SaveAttributeValues(IHasAttributes model, Rock.Web.Cache.Attribute attribute, List <Rock.Core.DTO.AttributeValue> newValues, int?personId) { Core.AttributeValueService attributeValueService = new Core.AttributeValueService(); var attributeValues = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, model.Id).ToList(); int i = 0; while (i < attributeValues.Count || i < newValues.Count) { Rock.Core.AttributeValue attributeValue; if (i < attributeValues.Count) { attributeValue = attributeValues[i]; } else { attributeValue = new Rock.Core.AttributeValue(); attributeValue.AttributeId = attribute.Id; attributeValue.EntityId = model.Id; attributeValue.Order = i; attributeValueService.Add(attributeValue, personId); } if (i >= newValues.Count) { attributeValueService.Delete(attributeValue, personId); } else { if (attributeValue.Value != newValues[i].Value) { attributeValue.Value = newValues[i].Value; } newValues[i] = attributeValue.DataTransferObject; } attributeValueService.Save(attributeValue, personId); i++; } model.AttributeValues[attribute.Key] = new KeyValuePair <string, List <Rock.Core.DTO.AttributeValue> >(attribute.Name, newValues); }
public Rock.Core.DTO.AttributeValue Get(string id) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get(int.Parse(id)); if (AttributeValue.Authorized("View", currentUser)) { return(AttributeValue.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this AttributeValue", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateAttributeValue( string apiKey, Rock.Core.DTO.AttributeValue AttributeValue ) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue existingAttributeValue = new Rock.Core.AttributeValue(); AttributeValueService.Add( existingAttributeValue, user.PersonId ); uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue); if (existingAttributeValue.IsValid) AttributeValueService.Save( existingAttributeValue, user.PersonId ); else throw new WebFaultException<string>( existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
/// <summary> /// Saves an attribute value. /// </summary> /// <param name="model">The model.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> /// <param name="personId">The person id.</param> public static void SaveAttributeValues( IHasAttributes model, Rock.Web.Cache.Attribute attribute, List<Rock.Core.DTO.AttributeValue> newValues, int? personId ) { Core.AttributeValueService attributeValueService = new Core.AttributeValueService(); var attributeValues = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, model.Id ).ToList(); int i = 0; while ( i < attributeValues.Count || i < newValues.Count ) { Rock.Core.AttributeValue attributeValue; if ( i < attributeValues.Count ) { attributeValue = attributeValues[i]; } else { attributeValue = new Rock.Core.AttributeValue(); attributeValue.AttributeId = attribute.Id; attributeValue.EntityId = model.Id; attributeValue.Order = i; attributeValueService.Add( attributeValue, personId ); } if ( i >= newValues.Count ) attributeValueService.Delete( attributeValue, personId ); else { if ( attributeValue.Value != newValues[i].Value ) attributeValue.Value = newValues[i].Value; newValues[i] = attributeValue.DataTransferObject; } attributeValueService.Save( attributeValue, personId ); i++; } model.AttributeValues[attribute.Key] = new KeyValuePair<string, List<Rock.Core.DTO.AttributeValue>>( attribute.Name, newValues ); }
/// <summary> /// Saves an attribute value. /// </summary> /// <param name="model">The model.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> /// <param name="personId">The person id.</param> public static void SaveAttributeValue( IHasAttributes model, Rock.Web.Cache.Attribute attribute, string newValue, int? personId ) { Core.AttributeValueService attributeValueService = new Core.AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, model.Id ).FirstOrDefault(); if ( attributeValue == null ) { attributeValue = new Rock.Core.AttributeValue(); attributeValue.AttributeId = attribute.Id; attributeValue.EntityId = model.Id; attributeValue.Order = 0; attributeValueService.Add( attributeValue, personId ); } attributeValue.Value = newValue; attributeValueService.Save( attributeValue, personId ); model.AttributeValues[attribute.Key] = new KeyValuePair<string, List<Rock.Core.DTO.AttributeValue>>( attribute.Name, new List<Rock.Core.DTO.AttributeValue>() { attributeValue.DataTransferObject } ); }
public void CreateAttributeValue( Rock.Core.DTO.AttributeValue AttributeValue ) { 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService(); Rock.Core.AttributeValue existingAttributeValue = new Rock.Core.AttributeValue(); AttributeValueService.Add( existingAttributeValue, currentUser.PersonId ); uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue); if (existingAttributeValue.IsValid) AttributeValueService.Save( existingAttributeValue, currentUser.PersonId ); else throw new WebFaultException<string>( existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }
/// <summary> /// Saves an attribute value. /// </summary> /// <param name="model">The model.</param> /// <param name="attribute">The attribute.</param> /// <param name="value">The value.</param> /// <param name="personId">The person id.</param> public static void SaveAttributeValue( IHasAttributes model, Rock.Web.Cache.Attribute attribute, string value, int? personId ) { Core.AttributeValueService attributeValueService = new Core.AttributeValueService(); Core.AttributeValue attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, model.Id ); if ( attributeValue == null ) { attributeValue = new Rock.Core.AttributeValue(); attributeValueService.Add( attributeValue, personId ); } attributeValue.AttributeId = attribute.Id; attributeValue.EntityId = model.Id; attributeValue.Value = value; attributeValueService.Save( attributeValue, personId ); model.AttributeValues[attribute.Key] = new KeyValuePair<string, string>( attribute.Name, value ); }