public Core.Attribute Update(Core.Attribute updatedAttribute) { var entity = db.Attributes.Attach(updatedAttribute); entity.State = EntityState.Modified; return(updatedAttribute); }
public ModifyResult Update(int personId, PersonAttribute attribute) { Arena.Core.Person person = new Arena.Core.Person(personId); var modifyResult = new ModifyResult(); try { Core.Attribute coreAttribute = null; if (attribute.AttributeID > 0) { coreAttribute = person.Attributes.FindByID(attribute.AttributeID); if (coreAttribute == null) { coreAttribute = new Core.PersonAttribute(attribute.AttributeID); person.Attributes.Add(coreAttribute); } } else { modifyResult.Successful = "False"; modifyResult.ErrorMessage = "Attribute ID is required."; return(modifyResult); } if (!coreAttribute.Allowed(Security.OperationType.Edit, Arena.Core.ArenaContext.Current.User, person)) { modifyResult.Successful = "False"; modifyResult.ErrorMessage = "Permission denied to edit attribute."; return(modifyResult); } coreAttribute.AttributeName = attribute.AttributeName; if (coreAttribute.AttributeType == Enums.DataType.String) { coreAttribute.StringValue = attribute.StringValue; } if (coreAttribute.AttributeType == Enums.DataType.DateTime) { coreAttribute.DateValue = attribute.DateValue.GetValueOrDefault(); } if (coreAttribute.AttributeType == Enums.DataType.Decimal) { coreAttribute.DecimalValue = attribute.DecimalValue.GetValueOrDefault(); } if (coreAttribute.AttributeType == Enums.DataType.Int) { coreAttribute.IntValue = attribute.IntValue.GetValueOrDefault(); } person.SaveAttributes(Arena.Core.ArenaContext.Current.Organization.OrganizationID, Arena.Core.ArenaContext.Current.User.Identity.Name); modifyResult.Successful = "True"; } catch (Exception e) { modifyResult.Successful = "False"; modifyResult.ErrorMessage = e.Message; } return(modifyResult); }
public IActionResult OnGet(int?productId, int?attributeId) { if (attributeId.HasValue) { Attribute = attributeData.GetById(attributeId.Value); } else { Attribute = new Core.Attribute(); } if (Attribute == null) { return(RedirectToPage("./NotFound")); } return(Page()); }
public void GenerateStats(StringList lines) { int num = fEnemies.Count; if (num == 0) { return; } lines.Add(""); lines.AddObject(" " + BaseLocale.GetStr(RS.rs_Killed), new JournalItem(JournalItem.SIT_KILLED, "", Colors.Red, JournalItem.DEFAULT_TURN)); for (int i = 0; i < num; i++) { Core.Attribute attr = fEnemies.GetItem(i); int id = attr.AID; int val = attr.AValue; CreatureEntry ce = (CreatureEntry)GlobalVars.nwrDB.GetEntry(id); lines.Add(" " + ce.GetNounDeclension(Number.nSingle, Case.cNominative) + ": " + Convert.ToString(val)); } }
/// <summary> /// Adds or Updates a <see cref="Rock.Core.Attribute"/> item for the attribute. /// </summary> /// <param name="property">The property.</param> /// <param name="entity">The entity.</param> /// <param name="entityQualifierColumn">The entity qualifier column.</param> /// <param name="entityQualifierValue">The entity qualifier value.</param> /// <param name="currentPersonId">The current person id.</param> /// <returns></returns> private static bool UpdateAttribute( Rock.Attribute.PropertyAttribute property, string entity, string entityQualifierColumn, string entityQualifierValue, int? currentPersonId ) { bool updated = false; Core.AttributeService attributeService = new Core.AttributeService(); Core.FieldTypeService fieldTypeService = new Core.FieldTypeService(); // Look for an existing attribute record based on the entity, entityQualifierColumn and entityQualifierValue Core.Attribute attribute = attributeService.GetByEntityAndEntityQualifierColumnAndEntityQualifierValueAndKey( entity, entityQualifierColumn, entityQualifierValue, property.Key ); if ( attribute == null ) { // If an existing attribute record doesn't exist, create a new one updated = true; attribute = new Core.Attribute(); attribute.Entity = entity; attribute.EntityQualifierColumn = entityQualifierColumn; attribute.EntityQualifierValue = entityQualifierValue; attribute.Key = property.Key; attribute.GridColumn = false; } else { // Check to see if the existing attribute record needs to be updated if ( attribute.Name != property.Name || attribute.Category != property.Category || attribute.DefaultValue != property.DefaultValue || attribute.Description != property.Description || attribute.Order != property.Order || attribute.FieldType.Assembly != property.FieldTypeAssembly || attribute.FieldType.Class != property.FieldTypeClass || attribute.Required != property.Required ) updated = true; } if ( updated ) { // Update the attribute attribute.Name = property.Name; attribute.Category = property.Category; attribute.Description = property.Description; attribute.DefaultValue = property.DefaultValue; attribute.Order = property.Order; attribute.Required = property.Required; // Try to set the field type by searching for an existing field type with the same assembly and class name if ( attribute.FieldType == null || attribute.FieldType.Assembly != property.FieldTypeAssembly || attribute.FieldType.Class != property.FieldTypeClass ) { attribute.FieldType = fieldTypeService.Queryable().FirstOrDefault( f => f.Assembly == property.FieldTypeAssembly && f.Class == property.FieldTypeClass ); } // If this is a new attribute, add it, otherwise remove the exiting one from the cache if ( attribute.Id == 0 ) attributeService.Add( attribute, currentPersonId ); else Rock.Web.Cache.Attribute.Flush( attribute.Id ); attributeService.Save( attribute, currentPersonId ); return true; } else return false; }
/// <summary> /// Adds or Updates a <see cref="Rock.Core.Attribute"/> item for the attribute. /// </summary> /// <param name="property">The property.</param> /// <param name="entity">The entity.</param> /// <param name="entityQualifierColumn">The entity qualifier column.</param> /// <param name="entityQualifierValue">The entity qualifier value.</param> /// <param name="currentPersonId">The current person id.</param> /// <returns></returns> private static bool UpdateAttribute(Rock.Attribute.PropertyAttribute property, string entity, string entityQualifierColumn, string entityQualifierValue, int?currentPersonId) { bool updated = false; Core.AttributeService attributeService = new Core.AttributeService(); Core.FieldTypeService fieldTypeService = new Core.FieldTypeService(); // Look for an existing attribute record based on the entity, entityQualifierColumn and entityQualifierValue Core.Attribute attribute = attributeService.GetByEntityAndEntityQualifierColumnAndEntityQualifierValueAndKey( entity, entityQualifierColumn, entityQualifierValue, property.Key); if (attribute == null) { // If an existing attribute record doesn't exist, create a new one updated = true; attribute = new Core.Attribute(); attribute.Entity = entity; attribute.EntityQualifierColumn = entityQualifierColumn; attribute.EntityQualifierValue = entityQualifierValue; attribute.Key = property.Key; attribute.GridColumn = false; } else { // Check to see if the existing attribute record needs to be updated if (attribute.Name != property.Name || attribute.Category != property.Category || attribute.DefaultValue != property.DefaultValue || attribute.Description != property.Description || attribute.Order != property.Order || attribute.FieldType.Assembly != property.FieldTypeAssembly || attribute.FieldType.Class != property.FieldTypeClass || attribute.Required != property.Required) { updated = true; } } if (updated) { // Update the attribute attribute.Name = property.Name; attribute.Category = property.Category; attribute.Description = property.Description; attribute.DefaultValue = property.DefaultValue; attribute.Order = property.Order; attribute.Required = property.Required; // Try to set the field type by searching for an existing field type with the same assembly and class name if (attribute.FieldType == null || attribute.FieldType.Assembly != property.FieldTypeAssembly || attribute.FieldType.Class != property.FieldTypeClass) { attribute.FieldType = fieldTypeService.Queryable().FirstOrDefault(f => f.Assembly == property.FieldTypeAssembly && f.Class == property.FieldTypeClass); } // If this is a new attribute, add it, otherwise remove the exiting one from the cache if (attribute.Id == 0) { attributeService.Add(attribute, currentPersonId); } else { Rock.Web.Cache.Attribute.Flush(attribute.Id); } attributeService.Save(attribute, currentPersonId); return(true); } else { return(false); } }
public Core.Attribute Add(Core.Attribute newAttribute) { db.Add(newAttribute); return(newAttribute); }