public IHttpActionResult PatchCustomerBySSN([FromODataUri]string ssnKey, EdmEntityObject delta)
        {
            IList<string> changedPropertyNames = delta.GetChangedPropertyNames().ToList();
            IEdmEntityObject originalCustomer = null;
            foreach (var customer in AlternateKeysDataSource.Customers)
            {
                object value;
                if (customer.TryGetPropertyValue("SSN", out value))
                {
                    string stringKey = (string)value;
                    if (ssnKey == stringKey)
                    {
                        originalCustomer = customer;
                    }
                }
            }

            if (originalCustomer == null)
            {
                return NotFound();
            }

            object nameValue;
            delta.TryGetPropertyValue("Name", out nameValue);
            //Assert.NotNull(nameValue);
            //string strName = Assert.IsType<string>(nameValue);
            dynamic original = originalCustomer;
            //original.Name = strName;
            original.Name = nameValue;

            return Ok(originalCustomer);
        }
        public IHttpActionResult GetName(string key)
        {
            // Get entity type from path.
            ODataPath path = Request.ODataProperties().Path;

            if (path.PathTemplate != "~/entityset/key/property")
            {
                return BadRequest("Not the correct property access request!");
            }

            PropertyAccessPathSegment property = path.Segments.Last() as PropertyAccessPathSegment;
            IEdmEntityType entityType = property.Property.DeclaringType as IEdmEntityType;

            // Create an untyped entity object with the entity type.
            EdmEntityObject entity = new EdmEntityObject(entityType);

            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], key, entity);

            object value = DataSourceProvider.GetProperty((string)Request.Properties[Constants.ODataDataSource], "Name", entity);

            if (value == null)
            {
                return NotFound();
            }

            string strValue = value as string;
            return Ok(strValue);
        }
        private static void BuildOrderss(IEdmModel model)
        {
            IEdmEntityType orderType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Order");

            Guid[] guids =
            {
                new Guid("196B3584-EF3D-41FD-90B4-76D59F9B929C"),
                new Guid("6CED5600-28BA-40EE-A2DF-E80AFADBE6C7"),
                new Guid("75036B94-C836-4946-8CC8-054CF54060EC"),
                new Guid("B3FF5460-6E77-4678-B959-DCC1C4937FA7"),
                new Guid("ED773C85-4E3C-4FC4-A3E9-9F1DA0A626DA")
            };

            IEdmEntityObject[] untypedOrders = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedOrder = new EdmEntityObject(orderType);
                untypedOrder.OrderId = i;
                untypedOrder.Name = string.Format("Order-{0}", i);
                untypedOrder.Token = guids[i];
                untypedOrder.Amount = 10 + i;
                untypedOrders[i] = untypedOrder;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(orderType, isNullable: false)));

            Orders = new EdmEntityObjectCollection(entityCollectionType, untypedOrders.ToList());
        }
        private static void BuildCustomers(IEdmModel model)
        {
            IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Customer");

            IEdmEntityObject[] untypedCustomers = new IEdmEntityObject[6];
            for (int i = 1; i <= 5; i++)
            {
                dynamic untypedCustomer = new EdmEntityObject(customerType);
                untypedCustomer.ID = i;
                untypedCustomer.Name = string.Format("Name {0}", i);
                untypedCustomer.SSN = "SSN-" + i + "-" + (100 + i);
                untypedCustomers[i-1] = untypedCustomer;
            }

            // create a special customer for "PATCH"
            dynamic customer = new EdmEntityObject(customerType);
            customer.ID = 6;
            customer.Name = "Name 6";
            customer.SSN = "SSN-6-T-006";
            untypedCustomers[5] = customer;

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(customerType, isNullable: false)));

            Customers = new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList());
        }
 public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
 {
     EdmEntityObject entity = new EdmEntityObject(entityType);
     entity.TrySetPropertyValue("Name", "Foo");
     entity.TrySetPropertyValue("ID", 100);
     collection.Add(entity);
     entity = new EdmEntityObject(entityType);
     entity.TrySetPropertyValue("Name", "Bar");
     entity.TrySetPropertyValue("ID", 101);
     collection.Add(entity);
 }
 public IHttpActionResult PutStatement(int key, int navKey, EdmEntityObject statementObject)
 {
     Statement newStatement = new Statement();
     var properties = typeof(Statement).GetProperties();
     foreach (PropertyInfo propertyInfo in properties)
     {
         object value;
         statementObject.TryGetPropertyValue(propertyInfo.Name, out value);
         propertyInfo.SetValue(newStatement, value);
     }
     return Ok(newStatement);
 }
        private IEdmEntityObject Createchool(int id, DateTimeOffset dto, IEdmStructuredType edmType)
        {
            IEdmNavigationProperty navigationProperty = edmType.DeclaredProperties.OfType<EdmNavigationProperty>().FirstOrDefault(e => e.Name == "School");
            if (navigationProperty == null)
            {
                return null;
            }

            EdmEntityObject entity = new EdmEntityObject(navigationProperty.ToEntityType());
            entity.TrySetPropertyValue("ID", id);
            entity.TrySetPropertyValue("CreatedDay", dto);
            return entity;
        }
        private IEdmEntityObject CreateDetailInfo(int id, string title, IEdmStructuredType edmType)
        {
            IEdmNavigationProperty navigationProperty = edmType.DeclaredProperties.OfType<EdmNavigationProperty>().FirstOrDefault(e => e.Name == "DetailInfo");
            if (navigationProperty == null)
            {
                return null;
            }

            EdmEntityObject entity = new EdmEntityObject(navigationProperty.ToEntityType());
            entity.TrySetPropertyValue("ID", id);
            entity.TrySetPropertyValue("Title", title);
            return entity;
        }
        // Get entityset(key)
        public IEdmEntityObject Get(string key)
        {
            // Get entity type from path.
            ODataPath path = Request.ODataProperties().Path;
            IEdmEntityType entityType = (IEdmEntityType)path.EdmType;

            // Create an untyped entity object with the entity type.
            EdmEntityObject entity = new EdmEntityObject(entityType);

            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], key, entity);

            return entity;
        }
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Foo");
            entity.TrySetPropertyValue("ID", 100);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(2016, 1, 19, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));
            collection.Add(entity);

            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "Bar");
            entity.TrySetPropertyValue("ID", 101);
            entity.TrySetPropertyValue("School", Createchool(99, new DateTimeOffset(1978, 11, 15, 1, 2, 3, TimeSpan.Zero), entity.ActualEdmType));

            collection.Add(entity);
        }
        public IHttpActionResult GetStatementFromPaymentInstument(int key, int navKey)
        {
            var payinPIs = _dataSource.Accounts.Single(a => a.AccountID == key).PayinPIs;
            var payinPI = payinPIs.Single(pi => pi.PaymentInstrumentID == navKey);
            var statement = payinPI.Statement;

            IEdmEntityType productType = GetEdmEntityTypeOfStatement();
            EdmEntityObject statementObject = new EdmEntityObject(productType);
            var properties = typeof(Statement).GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                statementObject.TrySetPropertyValue(propertyInfo.Name, propertyInfo.GetValue(statement));
            }
            return Ok(statementObject);
        }
Esempio n. 12
0
        public void Get(IEdmEntityTypeReference entityType, EdmEntityObjectCollection collection)
        {
            EdmEntityObject entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "abc");
            entity.TrySetPropertyValue("ID", 1);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(88, "abc_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
            entity = new EdmEntityObject(entityType);
            entity.TrySetPropertyValue("Name", "def");
            entity.TrySetPropertyValue("ID", 2);
            entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(99, "def_detailinfo", entity.ActualEdmType));

            collection.Add(entity);
        }
Esempio n. 13
0
        public IHttpActionResult PostUntypedSimpleOpenCustomer(EdmEntityObject customer)
        {
            // Verify there is a string dynamic property in OpenEntityType
            object nameValue;
            customer.TryGetPropertyValue("Name", out nameValue);
            Type nameType;
            customer.TryGetPropertyType("Name", out nameType);

            Assert.NotNull(nameValue);
            Assert.Equal(typeof(String), nameType);
            Assert.Equal("FirstName 6", nameValue);

            // Verify there is a collection of double dynamic property in OpenEntityType
            object doubleListValue;
            customer.TryGetPropertyValue("DoubleList", out doubleListValue);
            Type doubleListType;
            customer.TryGetPropertyType("DoubleList", out doubleListType);

            Assert.NotNull(doubleListValue);
            Assert.Equal(typeof(List<Double>), doubleListType);

            // Verify there is a collection of complex type dynamic property in OpenEntityType
            object addressesValue;
            customer.TryGetPropertyValue("Addresses", out addressesValue);

            Assert.NotNull(addressesValue);

            // Verify there is a complex type dynamic property in OpenEntityType
            object addressValue;
            customer.TryGetPropertyValue("Address", out addressValue);

            Type addressType;
            customer.TryGetPropertyType("Address", out addressType);

            Assert.NotNull(addressValue);
            Assert.Equal(typeof(EdmComplexObject), addressType);

            // Verify there is a collection of enum type dynamic property in OpenEntityType
            object favoriteColorsValue;
            customer.TryGetPropertyValue("FavoriteColors", out favoriteColorsValue);
            EdmEnumObjectCollection favoriteColors = favoriteColorsValue as EdmEnumObjectCollection;

            Assert.NotNull(favoriteColorsValue);
            Assert.NotNull(favoriteColors);
            Assert.Equal(typeof(EdmEnumObject), favoriteColors[0].GetType());

            // Verify there is an enum type dynamic property in OpenEntityType
            object favoriteColorValue;
            customer.TryGetPropertyValue("FavoriteColor", out favoriteColorValue);

            Assert.NotNull(favoriteColorValue);
            Assert.Equal("Red", ((EdmEnumObject)favoriteColorValue).Value);

            Type favoriteColorType;
            customer.TryGetPropertyType("FavoriteColor", out favoriteColorType);

            Assert.Equal(typeof(EdmEnumObject), favoriteColorType);

            // Verify there is a string dynamic property in OpenComplexType
            EdmComplexObject address = addressValue as EdmComplexObject;
            object cityValue;
            address.TryGetPropertyValue("City", out cityValue);
            Type cityType;
            address.TryGetPropertyType("City", out cityType);

            Assert.NotNull(cityValue);
            Assert.Equal(typeof(String), cityType);
            Assert.Equal("City 6", cityValue);

            return Ok(customer);
        }
        private static void BuildCompanies(IEdmModel model)
        {
            IEdmEntityType companyType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Company");

            IList<IEdmComplexObject> addresses = BuildAddrsses(model);

            IEdmEntityObject[] untypedCompanies = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedCompany = new EdmEntityObject(companyType);
                untypedCompany.ID = i;
                untypedCompany.Location = addresses[i];
                untypedCompanies[i] = untypedCompany;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(companyType, isNullable: false)));

            Companies = new EdmEntityObjectCollection(entityCollectionType, untypedCompanies.ToList());
        }
Esempio n. 15
0
        /// <summary>
        /// Handles a POST request to create an entity.
        /// </summary>
        /// <param name="edmEntityObject">The entity object to create.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that contains the creation result.</returns>
        public async Task<IHttpActionResult> Post(EdmEntityObject edmEntityObject, CancellationToken cancellationToken)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            ODataPath path = this.GetPath();
            IEdmEntitySet entitySet = path.NavigationSource as IEdmEntitySet;
            if (entitySet == null)
            {
                throw new NotImplementedException(Resources.InsertOnlySupportedOnEntitySet);
            }

            DataModificationEntry postEntry = new DataModificationEntry(
                entitySet.Name,
                path.EdmType.FullTypeName(),
                null,
                null,
                edmEntityObject.CreatePropertyDictionary());

            RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet();
            if (changeSetProperty == null)
            {
                ChangeSet changeSet = new ChangeSet();
                changeSet.Entries.Add(postEntry);

                SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken);
            }
            else
            {
                changeSetProperty.ChangeSet.Entries.Add(postEntry);

                await changeSetProperty.OnChangeSetCompleted();
            }

            return this.CreateCreatedODataResult(postEntry.Entity);
        }
Esempio n. 16
0
        private async Task<IHttpActionResult> Update(
            EdmEntityObject edmEntityObject,
            bool isFullReplaceUpdate,
            CancellationToken cancellationToken)
        {
            ODataPath path = this.GetPath();
            IEdmEntitySet entitySet = path.NavigationSource as IEdmEntitySet;
            if (entitySet == null)
            {
                throw new NotImplementedException(Resources.UpdateOnlySupportedOnEntitySet);
            }

            DataModificationEntry updateEntry = new DataModificationEntry(
                entitySet.Name,
                path.EdmType.FullTypeName(),
                RestierQueryBuilder.GetPathKeyValues(path),
                this.GetOriginalValues(),
                edmEntityObject.CreatePropertyDictionary());
            updateEntry.IsFullReplaceUpdate = isFullReplaceUpdate;

            RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet();
            if (changeSetProperty == null)
            {
                ChangeSet changeSet = new ChangeSet();
                changeSet.Entries.Add(updateEntry);

                SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken);
            }
            else
            {
                changeSetProperty.ChangeSet.Entries.Add(updateEntry);

                await changeSetProperty.OnChangeSetCompleted();
            }

            return this.CreateUpdatedODataResult(updateEntry.Entity);
        }
Esempio n. 17
0
        /// <summary>
        /// Handles a PATCH request to partially update an entity.
        /// </summary>
        /// <param name="edmEntityObject">The entity object to update.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that contains the updated result.</returns>
        public async Task<IHttpActionResult> Patch(EdmEntityObject edmEntityObject, CancellationToken cancellationToken)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            return await this.Update(edmEntityObject, false, cancellationToken);
        }
 private dynamic CreateOrder(int j)
 {
     dynamic order = new EdmEntityObject(OrderType);
     order.Id = j;
     order.ShippingAddress = CreateAddress(j);
     return order;
 }
 private dynamic CreateOrders(int i)
 {
     EdmEntityObject[] orders = new EdmEntityObject[i];
     for (int j = 0; j < i; j++)
     {
         dynamic order = new EdmEntityObject(OrderType);
         order.Id = j;
         order.ShippingAddress = CreateAddress(j);
         orders[j] = order;
     }
     var collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(OrderType, false))), orders);
     return collection;
 }
Esempio n. 20
0
        public IHttpActionResult PostUntypedSimpleOpenCustomer(EdmEntityObject customer)
        {
            // Verify there is a string dynamic property in OpenEntityType
            object nameValue;

            customer.TryGetPropertyValue("Name", out nameValue);
            Type nameType;

            customer.TryGetPropertyType("Name", out nameType);

            Assert.NotNull(nameValue);
            Assert.Equal(typeof(String), nameType);
            Assert.Equal("FirstName 6", nameValue);

            // Verify there is a collection of double dynamic property in OpenEntityType
            object doubleListValue;

            customer.TryGetPropertyValue("DoubleList", out doubleListValue);
            Type doubleListType;

            customer.TryGetPropertyType("DoubleList", out doubleListType);

            Assert.NotNull(doubleListValue);
            Assert.Equal(typeof(List <Double>), doubleListType);

            // Verify there is a collection of complex type dynamic property in OpenEntityType
            object addressesValue;

            customer.TryGetPropertyValue("Addresses", out addressesValue);

            Assert.NotNull(addressesValue);

            // Verify there is a complex type dynamic property in OpenEntityType
            object addressValue;

            customer.TryGetPropertyValue("Address", out addressValue);

            Type addressType;

            customer.TryGetPropertyType("Address", out addressType);

            Assert.NotNull(addressValue);
            Assert.Equal(typeof(EdmComplexObject), addressType);

            // Verify there is a collection of enum type dynamic property in OpenEntityType
            object favoriteColorsValue;

            customer.TryGetPropertyValue("FavoriteColors", out favoriteColorsValue);
            EdmEnumObjectCollection favoriteColors = favoriteColorsValue as EdmEnumObjectCollection;

            Assert.NotNull(favoriteColorsValue);
            Assert.NotNull(favoriteColors);
            Assert.Equal(typeof(EdmEnumObject), favoriteColors[0].GetType());

            // Verify there is an enum type dynamic property in OpenEntityType
            object favoriteColorValue;

            customer.TryGetPropertyValue("FavoriteColor", out favoriteColorValue);

            Assert.NotNull(favoriteColorValue);
            Assert.Equal("Red", ((EdmEnumObject)favoriteColorValue).Value);

            Type favoriteColorType;

            customer.TryGetPropertyType("FavoriteColor", out favoriteColorType);

            Assert.Equal(typeof(EdmEnumObject), favoriteColorType);

            // Verify there is a string dynamic property in OpenComplexType
            EdmComplexObject address = addressValue as EdmComplexObject;
            object           cityValue;

            address.TryGetPropertyValue("City", out cityValue);
            Type cityType;

            address.TryGetPropertyType("City", out cityType);

            Assert.NotNull(cityValue);
            Assert.Equal(typeof(String), cityType);
            Assert.Equal("City 6", cityValue);

            return(Ok(customer));
        }
Esempio n. 21
0
 public EdmEntityObject Get(string key, ODataQueryOptions queryOptions)
 {
     var cxt = queryOptions.Context;
     var entityType = cxt.ElementType as EdmEntityType;
     if (this.PermissionCheck != null && !this.PermissionCheck(MethodType.Get, entityType.Name))
     {
         throw new UnauthorizedAccessException();
     }
     var keyDefine = entityType.DeclaredKey.First();
     string cmdSql = "select {0} from [{1}] where [{2}]=@{2}";
     var cmdTxt = string.Format(cmdSql
         , queryOptions.ParseSelect()
         , cxt.Path.Segments[0].ToString()
         , keyDefine.Name);
     EdmEntityObject entity = new EdmEntityObject(entityType);
     using (DbAccess db = new DbAccess(this.ConnectionString))
     {
         db.ExecuteReader(cmdTxt,
             (reader) =>
             {
                 for (int i = 0; i < reader.FieldCount; i++)
                 {
                     reader.SetEntityPropertyValue(i, entity);
                 }
             },
             (par) => { par.AddWithValue("@" + keyDefine.Name, key.ChangeType(keyDefine.Type.PrimitiveKind())); },
             CommandType.Text);
     }
     return entity;
 }
Esempio n. 22
0
        private async Task<IHttpActionResult> Update(
            EdmEntityObject edmEntityObject,
            bool isFullReplaceUpdate,
            CancellationToken cancellationToken)
        {
            ODataPath path = this.GetPath();
            IEdmEntitySet entitySet = path.NavigationSource as IEdmEntitySet;
            if (entitySet == null)
            {
                throw new NotImplementedException(Resources.UpdateOnlySupportedOnEntitySet);
            }

            var propertiesInEtag = await this.GetOriginalValues(entitySet);
            if (propertiesInEtag == null)
            {
                throw new PreconditionRequiredException(Resources.PreconditionRequired);
            }

            // In case of type inheritance, the actual type will be different from entity type
            // This is only needed for put case, and does not need for patch case
            // For put request, it will create a new, blank instance of the entity.
            // copy over the key values and set any updated values from the client on the new instance.
            // Then apply all the properties of the new instance to the instance to be updated.
            // This will set any unspecified properties to their default value.
            var expectedEntityType = path.EdmType;
            var actualEntityType = path.EdmType as IEdmStructuredType;
            if (edmEntityObject.ActualEdmType != null)
            {
                expectedEntityType = edmEntityObject.ExpectedEdmType;
                actualEntityType = edmEntityObject.ActualEdmType;
            }

            DataModificationItem updateItem = new DataModificationItem(
                entitySet.Name,
                expectedEntityType.GetClrType(Api),
                actualEntityType.GetClrType(Api),
                DataModificationItemAction.Update,
                RestierQueryBuilder.GetPathKeyValues(path),
                propertiesInEtag,
                edmEntityObject.CreatePropertyDictionary(actualEntityType, api, false));
            updateItem.IsFullReplaceUpdateRequest = isFullReplaceUpdate;

            RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet();
            if (changeSetProperty == null)
            {
                ChangeSet changeSet = new ChangeSet();
                changeSet.Entries.Add(updateItem);

                SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken);
            }
            else
            {
                changeSetProperty.ChangeSet.Entries.Add(updateItem);

                await changeSetProperty.OnChangeSetCompleted(this.Request);
            }

            return this.CreateUpdatedODataResult(updateItem.Resource);
        }
Esempio n. 23
0
        /// <summary>
        /// Handles a POST request to create an entity.
        /// </summary>
        /// <param name="edmEntityObject">The entity object to create.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that contains the creation result.</returns>
        public async Task<IHttpActionResult> Post(EdmEntityObject edmEntityObject, CancellationToken cancellationToken)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            ODataPath path = this.GetPath();
            IEdmEntitySet entitySet = path.NavigationSource as IEdmEntitySet;
            if (entitySet == null)
            {
                throw new NotImplementedException(Resources.InsertOnlySupportedOnEntitySet);
            }

            // In case of type inheritance, the actual type will be different from entity type
            var expectedEntityType = path.EdmType;
            var actualEntityType = path.EdmType as IEdmStructuredType;
            if (edmEntityObject.ActualEdmType != null)
            {
                expectedEntityType = edmEntityObject.ExpectedEdmType;
                actualEntityType = edmEntityObject.ActualEdmType;
            }

            DataModificationItem postItem = new DataModificationItem(
                entitySet.Name,
                expectedEntityType.GetClrType(Api),
                actualEntityType.GetClrType(Api),
                DataModificationItemAction.Insert,
                null,
                null,
                edmEntityObject.CreatePropertyDictionary(actualEntityType, api, true));

            RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet();
            if (changeSetProperty == null)
            {
                ChangeSet changeSet = new ChangeSet();
                changeSet.Entries.Add(postItem);

                SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken);
            }
            else
            {
                changeSetProperty.ChangeSet.Entries.Add(postItem);

                await changeSetProperty.OnChangeSetCompleted(this.Request);
            }

            return this.CreateCreatedODataResult(postItem.Resource);
        }
Esempio n. 24
0
 public object GetProperty(string property, EdmEntityObject entity)
 {
     object value;
     entity.TryGetPropertyValue(property, out value);
     return value;
 }
        private static void BuildPeople(IEdmModel model)
        {
            IEdmEntityType personType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Person");

            IEdmEntityObject[] untypedPeople = new IEdmEntityObject[5];
            for (int i = 0; i < 5; i++)
            {
                dynamic untypedPerson = new EdmEntityObject(personType);
                untypedPerson.ID = i;
                untypedPerson.Country = new[] { "Great Britain", "China", "United States", "Russia", "Japan" }[i];
                untypedPerson.Passport = new[] { "1001", "2010", "9999", "3199992", "00001"}[i];
                untypedPeople[i] = untypedPerson;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(personType, isNullable: false)));

            People = new EdmEntityObjectCollection(entityCollectionType, untypedPeople.ToList());
        }
Esempio n. 26
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return _untypedSimpleOpenCustormers;
            }
            EdmEntityType customerType = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);
            customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
            EdmEntityObject customer = new EdmEntityObject(customerType);
            customer.TrySetPropertyValue("CustomerId", 1);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            EdmEnumType colorType = new EdmEnumType("NS", "Color");
            colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(0)));

            EdmEnumObject color = new EdmEnumObject(colorType, "Red");
            EdmEnumObject color2 = new EdmEnumObject(colorType, "0");
            EdmEnumObject color3 = new EdmEnumObject(colorType, "Red");
            customer.TrySetPropertyValue("Color", color);

            List<IEdmEnumObject> colorList = new List<IEdmEnumObject>();
            colorList.Add(color);
            colorList.Add(color2);
            colorList.Add(color3);
            IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false)));
            EdmEnumObjectCollection colors = new EdmEnumObjectCollection(enumCollectionType, colorList);
            customer.TrySetPropertyValue("Colors", colors);
            customer.TrySetPropertyValue("DeclaredColors", colors);

            //Add Addresses complex(collection) property 
            EdmComplexType addressType = new EdmComplexType("NS", "Address", null, false, true);
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);

            EdmComplexObject address = new EdmComplexObject(addressType);
            address.TrySetPropertyValue("Street", "No1");
            EdmComplexObject address2 = new EdmComplexObject(addressType);
            address2.TrySetPropertyValue("Street", "No2");

            List<IEdmComplexObject> addressList = new List<IEdmComplexObject>();
            addressList.Add(address);
            addressList.Add(address2);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false)));
            EdmComplexObjectCollection addresses = new EdmComplexObjectCollection(complexCollectionType, addressList);
            customer.TrySetPropertyValue("DeclaredAddresses", addresses);

            EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));
            customers.Add(customer);
            _untypedSimpleOpenCustormers = customers;
            return _untypedSimpleOpenCustormers;
        }
Esempio n. 27
0
        EdmEntityObjectCollection Get(IEdmCollectionType edmType, string sqlCmd, List<ExpandedNavigationSelectItem> expands = null)
        {
            var entityType = edmType.ElementType.AsEntity();

            EdmEntityObjectCollection collection = new EdmEntityObjectCollection(new EdmCollectionTypeReference(edmType));
            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                db.ExecuteReader(sqlCmd, (reader) =>
                {
                    EdmEntityObject entity = new EdmEntityObject(entityType);
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        reader.SetEntityPropertyValue(i, entity);
                    }
                    if (expands != null)
                    {
                        foreach (var expanded in expands)
                        {
                            List<string> condition = new List<string>();
                            foreach (NavigationPropertySegment item in expanded.PathToNavigationProperty)
                            {
                                foreach (var p in item.NavigationProperty.ReferentialConstraint.PropertyPairs)
                                {
                                    condition.Add(packCondition(p, reader[p.DependentProperty.Name]));
                                }
                            }
                            var ss = Get(expanded.NavigationSource.Type as IEdmCollectionType, BuildSqlQueryCmd(expanded, string.Join(" and ", condition)));
                            bool t = entity.TrySetPropertyValue(expanded.NavigationSource.Name, ss);
                        }
                    }
                    collection.Add(entity);

                }, null, CommandType.Text);
            }
            return collection;
        }
Esempio n. 28
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return(_untypedSimpleOpenCustormers);
            }
            EdmEntityType customerType = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);

            customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
            EdmEntityObject customer = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("CustomerId", 1);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            EdmEnumType colorType = new EdmEnumType("NS", "Color");

            colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(0)));

            EdmEnumObject color  = new EdmEnumObject(colorType, "Red");
            EdmEnumObject color2 = new EdmEnumObject(colorType, "0");
            EdmEnumObject color3 = new EdmEnumObject(colorType, "Red");

            customer.TrySetPropertyValue("Color", color);

            List <IEdmEnumObject> colorList = new List <IEdmEnumObject>();

            colorList.Add(color);
            colorList.Add(color2);
            colorList.Add(color3);
            IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false)));
            EdmEnumObjectCollection     colors             = new EdmEnumObjectCollection(enumCollectionType, colorList);

            customer.TrySetPropertyValue("Colors", colors);
            customer.TrySetPropertyValue("DeclaredColors", colors);

            //Add Addresses complex(collection) property
            EdmComplexType addressType = new EdmComplexType("NS", "Address", null, false, true);

            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);

            EdmComplexObject address = new EdmComplexObject(addressType);

            address.TrySetPropertyValue("Street", "No1");
            EdmComplexObject address2 = new EdmComplexObject(addressType);

            address2.TrySetPropertyValue("Street", "No2");

            List <IEdmComplexObject> addressList = new List <IEdmComplexObject>();

            addressList.Add(address);
            addressList.Add(address2);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false)));
            EdmComplexObjectCollection  addresses             = new EdmComplexObjectCollection(complexCollectionType, addressList);

            customer.TrySetPropertyValue("DeclaredAddresses", addresses);

            EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));

            customers.Add(customer);
            _untypedSimpleOpenCustormers = customers;
            return(_untypedSimpleOpenCustormers);
        }
 public void Get(string key, EdmEntityObject entity)
 {
     entity.TrySetPropertyValue("Name", "Foo");
     entity.TrySetPropertyValue("ID", int.Parse(key));
 }
 public static void Get(string dataSourceName, string key, EdmEntityObject entity)
 {
     GetDataSource(dataSourceName).Get(key, entity);
 }
Esempio n. 31
0
 public IHttpActionResult Get(int key)
 {
     IEdmModel model = Request.ODataProperties().Model;
     IEdmEntityType entityType = model.SchemaElements.OfType<IEdmEntityType>().First(c => c.Name == "Customer");
     EdmEntityObject customer = new EdmEntityObject(entityType);
     customer.TrySetPropertyValue("ID", key);
     customer.TrySetPropertyValue("Name", "Sam");
     return Ok(customer);
 }
        public IHttpActionResult Get()
        {
            IEdmEntityObject[] untypedCustomers = new EdmEntityObject[20];
            for (int i = 0; i < 20; i++)
            {
                dynamic untypedCustomer = new EdmEntityObject(CustomerType);
                untypedCustomer.Id = i;
                untypedCustomer.Name = string.Format("Name {0}", i);
                untypedCustomer.Orders = CreateOrders(i);
                untypedCustomer.Addresses = CreateAddresses(i);
                untypedCustomer.FavoriteNumbers = Enumerable.Range(0, i).ToArray();
                untypedCustomers[i] = untypedCustomer;
            }

            IEdmCollectionTypeReference entityCollectionType =
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmEntityTypeReference(CustomerType, isNullable: false)));

            return Ok(new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList()));
        }