asp.net-web-api2

Get selected values after joining multiple tables in Entity Framework 6 using Lambda

送分小仙女□ 提交于 2019-12-04 05:49:02
问题 I have three tables ( simplified example for this issue ): Models are generated using EntityFramework Database-First approach. OwnerModel public partial class Owner { public Owner() { this.OwnerDogMapper= new HashSet<OwnerDogMapper>(); } public string OwnerId { get; set; } public string OwnerName { get; set; } public virtual ICollection<OwnerDogMapper> OwnerDogMapper{ get; set; } } DogTable public partial class Dog { public Dog() { this.OwnerDogMapper= new HashSet<OwnerDogMapper>(); } public

How to post and receive a file with web api

旧巷老猫 提交于 2019-12-04 05:47:26
问题 I have a Api Post method that I want to be able to accept any file type and that looks like this: [HttpPost] public async Task<IHttpActionResult> Post() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); if (provider.Contents.Count != 1) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode

Possible to post ODataQueryOptions from the Http Request body?

爱⌒轻易说出口 提交于 2019-12-04 05:43:53
I'm implementing a Web API interface to support some fairly complex queries to run against it and have run up against an issue with the maximum request URI length. The definition of my Web API method looks like this (using Automapper to perform the DTO projections): public IQueryable<ReportModel> Get(ODataQueryOptions<Report> queryOptions) { var query = DbContext.Query<Report>(); return (queryOptions.ApplyTo(query) as IQueryable<Report>).WithTranslations().Project(MappingEngine).To<ReportModel>().WithTranslations(); } My request consists of a dynamically built OData query including a

How do I add properties to a Web API Response that I do not store in my DB?

有些话、适合烂在心里 提交于 2019-12-04 05:25:32
问题 I am building a C# Web API using Entity Framework 6.0. I have the simplest User Class with 3 properties that I persist on SQL into a User Table with 3 corresponding columns where UserID is its the Primary Key. public partial class User { public string UserID {get; set;} public string FirstName {get; set;} public string LastName {get; set;} } I want to add to the Web API two output-only properties on the fly that I do not care to store in my DB. I use these properties to communicate to the

WebAPI CORS - why is the OPTIONS request making its way into my Controller?

ぐ巨炮叔叔 提交于 2019-12-04 05:12:21
I have CORS working with the following: [System.Web.Http.HttpPut] [System.Web.Http.AcceptVerbs("OPTIONS")] [System.Web.Http.Route("api/exercise")] public HttpResponseMessage UpdateExercise(Exercise exercise) { try { _adminService.UpdateExercise(exercise); return Request.CreateResponse(HttpStatusCode.OK, "Success"); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.InternalServerError, e); } } In my global.asax : protected void Application_BeginRequest() { if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS") { Response.Flush(); } } But something

How do I serialize an IdentityUser reference in Web API 2.2?

心已入冬 提交于 2019-12-04 05:09:28
问题 The Visual Studio "Web API" project template includes endpoints for handling registration, authentication, and authorization of users. In a production application, however, users will typically be associated with other Entities as well, such as: public class Post { public Post() {}; public int Id { get; set; } public ApplicationUser User { get; set; } } In these scenarios, the ApplicationUser class (which is derived from IdentityUser ) cannot be serialized. Attempting to do so will yield an

ApiExplorer does not recognize route attributes with custom type

喜欢而已 提交于 2019-12-04 05:05:30
问题 I have a project where I want to use route attributes with a custom type. The following code where I have the custom type as a query parameter works fine and the help page displays the custom type. // GET api/values?5,6 [Route("api/values")] public string Get(IntegerListParameter ids) { return "value"; } WebApi.HelpPage gives the following documentation Help:Page If I change the code to use route attributes, the result is that I get an empty help page. // GET api/values/5,6 [Route("api/values

Breeze filtering .Expand on server side

泄露秘密 提交于 2019-12-04 04:33:03
问题 I'm trying out BreezeJS . There is a requirement that I can use .expand in the client side code, but based on the role of the user, the server side will not return all the records for the .expand requested type. I tried to create a custom BreezeQueryable attribute and override a method to completely filter out the extra data first just to try. But it threw an exception. I don't see any entry point where I can do that on the server side. Please guide me in the right direction, or let me know

Generic Web Api method

喜欢而已 提交于 2019-12-04 04:30:36
I've some classes like CustomerModel or CustomerDetailsModel which are inherting from ModelBase . Also i don't want to introduce subclasses for each modeltype. In one case have a post method foreach. So i could manually create multiple routes to call a method which looks like Handle<T>(T model) where T : ModelBase They only differ in the path the were called. For example: baseurl/api/customer => CustomerModel baseurl/api/customerdetails => CustomerDetailsModel I want to implement a generic web api method like [HttpPost] void Post<T>(T model) where T : ModelBase If I simply create a generic

webapi, how to read the file from a POST/PUT action with custom model binder

梦想与她 提交于 2019-12-04 02:24:08
问题 I have the following react component, which apparently its working fine: import React, { Component } from 'react'; import { Row, Col } from 'antd'; import PageHeader from '../../components/utility/pageHeader'; import Box from '../../components/utility/box'; import LayoutWrapper from '../../components/utility/layoutWrapper.js'; import ContentHolder from '../../components/utility/contentHolder'; import basicStyle from '../../settings/basicStyle'; import IntlMessages from '../../components