public IHttpActionResult Post(IEdmEntityObject customer) { if (!ModelState.IsValid) { return(BadRequest("customer is null")); } postedCustomer = customer; object id; customer.TryGetPropertyValue("Id", out id); return(Created(Url.CreateODataLink(new EntitySetPathSegment("UntypedCustomer"), new KeyValuePathSegment(id.ToString())), customer)); }
public IActionResult GetLocations(int key) { IEdmEntityObject movie = DataSource.GetMovie(key); if (movie != null) { if (movie.TryGetPropertyValue("Locations", out object value)) { return(Ok((EdmComplexObjectCollection)value)); } } return(NotFound()); }
protected object GetPropertyValue(IEdmEntityObject p, string attributeName, object attributeValue) { if (attributeValue != null) { //specific null handling coz Equals and other aspects would need this return(attributeValue != null ? attributeValue : "--NULL--"); } else { p.TryGetPropertyValue(attributeName, out object value); //specific null handling coz Equals and other aspects would need this return(value != null ? value : "--NULL--"); } }
public IActionResult Post([FromBody]IEdmEntityObject customer) { if (!ModelState.IsValid) { return BadRequest("customer is null"); } postedCustomer = customer; object id; customer.TryGetPropertyValue("Id", out id); IEdmEntitySet entitySet = Request.GetModel().EntityContainer.FindEntitySet("TypelessCustomers"); return Created(Request.CreateODataLink(new EntitySetSegment(entitySet), new KeySegment(new[] { new KeyValuePair<string, object>("Id", id) }, entitySet.EntityType(), null)), customer); }
public IEdmEntityObject GetCategoryFromProduct(int key) { IEdmEntityObject product = Products.Single(p => HasId(p, key)); object category; if (product.TryGetPropertyValue("Category", out category)) { return((IEdmEntityObject)category); } else { return(null); } }
public IActionResult Get([FromODataUri] int key) { object id; if (postedCustomer == null || !postedCustomer.TryGetPropertyValue("Id", out id) || key != (int)id) { return BadRequest("The key isn't the one posted to the customer"); } ODataQueryContext context = new ODataQueryContext(Request.GetModel(), CustomerType, path: null); ODataQueryOptions query = new ODataQueryOptions(context, Request); if (query.SelectExpand != null) { Request.ODataFeature().SelectExpandClause = query.SelectExpand.SelectExpandClause; } return Ok(postedCustomer); }
public IHttpActionResult Patch(int key, IEdmEntityObject entity) { object value; if (entity.TryGetPropertyValue("Name", out value)) { string name = value as string; if (name != null) { if (name == "Sam") { return(Ok(name)); } } } return(BadRequest("Not My input.")); }
public int Replace(string key, IEdmEntityObject entity) { string cmdTemplate = "update [{0}] set {1} where {2} "; var entityType = entity.GetEdmType().Definition as EdmEntityType; if (this.PermissionCheck != null && !this.PermissionCheck(MethodType.Replace, entityType.Name)) { throw new UnauthorizedAccessException(); } var keyName = entityType.DeclaredKey.First().Name; List<string> cols = new List<string>(); List<string> pars = new List<string>(); List<SqlParameter> sqlpars = new List<SqlParameter>(); object v = null; foreach (var p in entityType.Properties()) { entity.TryGetPropertyValue(p.Name, out v); cols.Add(string.Format("[{0}]", p.Name)); pars.Add("@" + p.Name); sqlpars.Add(new SqlParameter("@" + p.Name, v == null ? DBNull.Value : v)); } int rtv; using (DbAccess db = new DbAccess(this.ConnectionString)) { rtv = db.ExecuteNonQuery(string.Format(cmdTemplate, entityType.Name, string.Join(", ", cols), string.Join(", ", pars)) , (dbpars) => { dbpars.AddRange(sqlpars.ToArray()); }, CommandType.Text); } return rtv; }
public int Merge(string key, IEdmEntityObject entity) { string cmdTemplate = "update [{0}] set {1} where [{2}]=@{2} "; var entityType = entity.GetEdmType().Definition as EdmEntityType; if (this.PermissionCheck != null && !this.PermissionCheck(MethodType.Merge, entityType.Name)) { throw new UnauthorizedAccessException(); } var keyDefine = entityType.DeclaredKey.First(); List<string> cols = new List<string>(); List<SqlParameter> sqlpars = new List<SqlParameter>(); object v = null; foreach (var p in (entity as Delta).GetChangedPropertyNames()) { entity.TryGetPropertyValue(p, out v); cols.Add(string.Format("[{0}]=@{0}", p)); sqlpars.Add(new SqlParameter("@" + p, v)); } if (cols.Count == 0) return 0; sqlpars.Add(new SqlParameter("@" + keyDefine.Name, key.ChangeType(keyDefine.Type.PrimitiveKind()))); int rtv; using (DbAccess db = new DbAccess(this.ConnectionString)) { rtv = db.ExecuteNonQuery(string.Format(cmdTemplate, entityType.Name, string.Join(", ", cols), keyDefine.Name) , (dbpars) => { dbpars.AddRange(sqlpars.ToArray()); }, CommandType.Text); } return rtv; }
public string Create(IEdmEntityObject entity) { var edmType = entity.GetEdmType(); var table = (edmType.Definition as EdmEntityType).Name; if (this.PermissionCheck != null && !this.PermissionCheck(MethodType.Create, table)) { throw new UnauthorizedAccessException(); } object rtv = null; string cmdTemplate = "insert into [{0}] ({1}) values ({2}) select SCOPE_IDENTITY() "; List<string> cols = new List<string>(); List<string> pars = new List<string>(); List<SqlParameter> sqlpars = new List<SqlParameter>(); object v = null; foreach (var p in (entity as Delta).GetChangedPropertyNames()) { entity.TryGetPropertyValue(p, out v); cols.Add(string.Format("[{0}]", p)); pars.Add("@" + p); sqlpars.Add(new SqlParameter("@" + p, v)); } using (DbAccess db = new DbAccess(this.ConnectionString)) { rtv = db.ExecuteScalar(string.Format(cmdTemplate, table, string.Join(", ", cols), string.Join(", ", pars)) , (dbpars) => { dbpars.AddRange(sqlpars.ToArray()); }, CommandType.Text); } return rtv.ToString(); }
public IHttpActionResult Post(IEdmEntityObject customer) { if (!ModelState.IsValid) { return BadRequest("customer is null"); } postedCustomer = customer; object id; customer.TryGetPropertyValue("Id", out id); return Created(Url.CreateODataLink(new EntitySetPathSegment("UntypedCustomer"), new KeyValuePathSegment(id.ToString())), customer); }
protected object GetPropertyValue(IEdmEntityObject p, string attributeName) { p.TryGetPropertyValue(attributeName, out object value); return(value != null ? value : null); }
private object GetPropertyValue(IEdmEntityObject p, string attributeName) { p.TryGetPropertyValue(attributeName, out object value); return(value); }
private bool HasId(IEdmEntityObject product, int key) { object id; return(product.TryGetPropertyValue("Id", out id) && (int)id == key); }
private bool HasId(IEdmEntityObject product, int key) { object id; return product.TryGetPropertyValue("Id", out id) && (int)id == key; }