// Any customized logic needed after persist called can be added here. // InnerProcessor call related OnUpdated|Inseted|Deleted<EntitySet> methods public Task OnChangeSetItemProcessedAsync(SubmitContext context, ChangeSetItem item , CancellationToken cancellationToken) { var dataModificationItem = item as DataModificationItem; if (dataModificationItem != null) { object myEntity = dataModificationItem.Resource; string entitySetName = dataModificationItem.ResourceSetName; DataModificationItemAction operation = dataModificationItem.DataModificationItemAction; // In case of insert, the request URL has no key, and request body may not have key neither as the key may be generated by database var keyAttrbiutes = new Dictionary <string, object>(); var keyConvention = new Dictionary <string, object>(); //var entityTypeName = myEntity.GetType().Name; // PropertyInfo[] properties = myEntity.GetType().GetProperties(); var et = myEntity as IEntity; KeyValModel _user = null; var C_user = new BaseController().getCurUser(); if (C_user != null) { _user = new KeyValModel { Key = C_user.EmpCode, Val = C_user.EmpName }; } switch (operation) { case DataModificationItemAction.Insert: et.Create(_user); break; case DataModificationItemAction.Remove: et.Remove(_user); break; case DataModificationItemAction.Undefined: break; case DataModificationItemAction.Update: et.Modify(_user); break; default: break; } } return(InnerProcessor.OnChangeSetItemProcessedAsync(context, item, cancellationToken)); }
public Task OnChangeSetItemProcessedAsync(SubmitContext context, ChangeSetItem item, CancellationToken cancellationToken) { var dataModificationItem = item as DataModificationItem; if (dataModificationItem != null) { object myEntity = dataModificationItem.Resource; string entitySetName = dataModificationItem.ResourceSetName; DataModificationItemAction operation = dataModificationItem.DataModificationItemAction; // In case of insert, the request URL has no key, and request body may not have key neither as the key may be generated by database var keyAttrbiutes = new Dictionary <string, object>(); var keyConvention = new Dictionary <string, object>(); var entityTypeName = myEntity.GetType().Name; PropertyInfo[] properties = myEntity.GetType().GetProperties(); foreach (PropertyInfo property in properties) { var attribute = Attribute.GetCustomAttribute(property, typeof(KeyAttribute)) as KeyAttribute; var propName = property.Name; // This is getting key with Key attribute defined if (attribute != null) // This property has a KeyAttribute { // Do something, to read from the property: object val = property.GetValue(myEntity); keyAttrbiutes.Add(propName, val); } // This is getting key based on convention else if (propName.ToLower().Equals("id") || propName.ToLower().Equals(entityTypeName.ToLower() + "id")) { object val = property.GetValue(myEntity); keyConvention.Add(propName, val); } } if (keyAttrbiutes.Count > 0) { // Use property with key attribute as keys } else if (keyConvention.Count > 0) { // Key is defined based on convention } } return(Inner.OnChangeSetItemProcessedAsync(context, item, cancellationToken)); }
/// <summary> /// Initializes a new instance of the <see cref="DataModificationItem" /> class. /// </summary> /// <param name="resourceSetName"> /// The name of the resource set in question. /// </param> /// <param name="expectedResourceType"> /// The type of the expected resource type in question. /// </param> /// <param name="actualResourceType"> /// The type of the actual resource type in question. /// </param> /// <param name="action"> /// The DataModificationItemAction for the request. /// </param> /// <param name="resourceKey"> /// The key of the resource being modified. /// </param> /// <param name="originalValues"> /// Any original values of the resource that are known. /// </param> /// <param name="localValues"> /// The local values of the resource. /// </param> public DataModificationItem( string resourceSetName, Type expectedResourceType, Type actualResourceType, DataModificationItemAction action, IReadOnlyDictionary <string, object> resourceKey, IReadOnlyDictionary <string, object> originalValues, IReadOnlyDictionary <string, object> localValues) : base(ChangeSetItemType.DataModification) { Ensure.NotNull(resourceSetName, "resourceSetName"); Ensure.NotNull(expectedResourceType, "expectedResourceType"); this.ResourceSetName = resourceSetName; this.ExpectedResourceType = expectedResourceType; this.ActualResourceType = actualResourceType; this.ResourceKey = resourceKey; this.OriginalValues = originalValues; this.LocalValues = localValues; this.DataModificationItemAction = action; }
/// <summary> /// Initializes a new instance of the <see cref="DataModificationItem" /> class. /// </summary> /// <param name="entitySetName"> /// The name of the entity set in question. /// </param> /// <param name="expectedEntityType"> /// The type of the expected entity type in question. /// </param> /// <param name="actualEntityType"> /// The type of the actual entity type in question. /// </param> /// <param name="action"> /// The DataModificationItemAction for the request. /// </param> /// <param name="entityKey"> /// The key of the entity being modified. /// </param> /// <param name="originalValues"> /// Any original values of the entity that are known. /// </param> /// <param name="localValues"> /// The local values of the entity. /// </param> public DataModificationItem( string entitySetName, Type expectedEntityType, Type actualEntityType, DataModificationItemAction action, IReadOnlyDictionary <string, object> entityKey, IReadOnlyDictionary <string, object> originalValues, IReadOnlyDictionary <string, object> localValues) : base(ChangeSetItemType.DataModification) { Ensure.NotNull(entitySetName, "entitySetName"); Ensure.NotNull(expectedEntityType, "expectedEntityType"); this.EntitySetName = entitySetName; this.ExpectedEntityType = expectedEntityType; this.ActualEntityType = actualEntityType; this.EntityKey = entityKey; this.OriginalValues = originalValues; this.LocalValues = localValues; this.DataModificationItemAction = action; }
/// <summary> /// Initializes a new instance of the <see cref="DataModificationItem" /> class. /// </summary> /// <param name="resourceSetName"> /// The name of the resource set in question. /// </param> /// <param name="expectedResourceType"> /// The type of the expected resource type in question. /// </param> /// <param name="actualResourceType"> /// The type of the actual resource type in question. /// </param> /// <param name="action"> /// The DataModificationItemAction for the request. /// </param> /// <param name="resourceKey"> /// The key of the resource being modified. /// </param> /// <param name="originalValues"> /// Any original values of the resource that are known. /// </param> /// <param name="localValues"> /// The local values of the resource. /// </param> public DataModificationItem( string resourceSetName, Type expectedResourceType, Type actualResourceType, DataModificationItemAction action, IReadOnlyDictionary<string, object> resourceKey, IReadOnlyDictionary<string, object> originalValues, IReadOnlyDictionary<string, object> localValues) : base(ChangeSetItemType.DataModification) { Ensure.NotNull(resourceSetName, "resourceSetName"); Ensure.NotNull(expectedResourceType, "expectedResourceType"); this.ResourceSetName = resourceSetName; this.ExpectedResourceType = expectedResourceType; this.ActualResourceType = actualResourceType; this.ResourceKey = resourceKey; this.OriginalValues = originalValues; this.LocalValues = localValues; this.DataModificationItemAction = action; }