void lvAttributeValues_ItemUpdating(object sender, ListViewUpdateEventArgs e) { PlaceHolder phEditValue = lvAttributeValues.EditItem.FindControl("phEditValue") as PlaceHolder; if (phEditValue != null && phEditValue.Controls.Count == 1) { string value = _attribute.FieldType.Field.GetEditValue(phEditValue.Controls[0], _attribute.QualifierValues); var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.Get(( int )e.Keys["Id"]); if (attributeValue == null) { attributeValue = new AttributeValue(); attributeValueService.Add(attributeValue, _currentPersonId); attributeValue.AttributeId = _attribute.Id; attributeValue.EntityId = _model.Id; } attributeValue.Value = value; attributeValueService.Save(attributeValue, _currentPersonId); _model.LoadAttributes(); } lvAttributeValues.EditIndex = -1; BindData(); }
public virtual HttpResponseMessage SetAttributeValue(int id, string attributeKey, string attributeValue) { T model; if (!Service.TryGet(id, out model)) { throw new HttpResponseException(HttpStatusCode.NotFound); } CheckCanEdit(model); Rock.Attribute.IHasAttributes modelWithAttributes = model as Rock.Attribute.IHasAttributes; if (modelWithAttributes != null) { using (var rockContext = new RockContext()) { modelWithAttributes.LoadAttributes(rockContext); Rock.Web.Cache.AttributeCache attributeCache = modelWithAttributes.Attributes.ContainsKey(attributeKey) ? modelWithAttributes.Attributes[attributeKey] : null; if (attributeCache != null) { if (!attributeCache.IsAuthorized(Rock.Security.Authorization.EDIT, this.GetPerson())) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { ReasonPhrase = string.Format("Not authorized to edit {0} on {1}", modelWithAttributes.GetType().GetFriendlyTypeName(), attributeKey) }); } Rock.Attribute.Helper.SaveAttributeValue(modelWithAttributes, attributeCache, attributeValue, rockContext); var response = ControllerContext.Request.CreateResponse(HttpStatusCode.Accepted, modelWithAttributes.Id); return(response); } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = string.Format("{0} does not have a {1} attribute", modelWithAttributes.GetType().GetFriendlyTypeName(), attributeKey) }); } } } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "specified item does not have attributes" }); } }