'POST method is working on POSTMAN but results are not being shown in SQL Server

I am trying to connect a Web API from Visual Studio which is connected with database using database first model but for some reason any data that I am trying to enter using POSTMAN POST method is not reflecting back in SQL Server.

Here is the code that I wrote in VS in my Web API project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using try43.Models;

namespace try43.Controllers
{
   
    public class LoginController : ApiController
    {
        [HttpPost]
        public HttpResponseMessage Login([FromBody] Customer customer)
        {
            ProjectDbContext db = new ProjectDbContext();
            db.Customers.Add(customer);
            return Request.CreateResponse(HttpStatusCode.OK, customer);
        }
    }
}

and this is WebApIConfig.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Web.Http;
using System.Web.Http.Cors;

namespace try43
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
        }
    }
}

Postman is able to show this page:

the postman is able to show this page



Solution 1:[1]

You're missing

db.SaveChanges();

To tell EF to save your changes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin HolĂ˝