Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

WEB API With EntityFramework - Post multiple parameters

$
0
0

Hi, 

I need a help.

My Project has the following structure:

  • Project.Domain (Models: Person)
  • Project.Data(Mapping Person and DataContext)
  • Project.API(Controllers, etc)

In my class Person:

 public class Person
 {
        public int Id { get; set; }

        public int IdReg { get; set; }

        public byte[] Image { get; set; }

        public DateTime DateReg { get; set; }
  }

So, in my PersonController, i have the following  method:

 [HttpPost]
        [Route("people")]
        public HttpResponseMessage PostPerson(Person person)
        {

            if (person == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            try
            {

                db.People.Add(person);

                db.SaveChanges();

                var result = person;
                return Request.CreateResponse(HttpStatusCode.OK, result);

            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Failed to insert person");
            }

        }

But, I using PostMan to test my Api, and passing the parameters, i get some error, causei dont know how to pass or get the image!

{
"Message": "The request entity's media type 'multipart/form-data' is not supported for this resource.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Person' from content with media type 'multipart/form-data'.",
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " em System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n em System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
}

Any help?


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>