title: Internal error 500 on POST web api
body: <p>I have a problem with my web api application. I get an internal error 500 when i try to post(save) a new user in my db.
  The function bellow is the one that i use to make the client call.    </p>
  
  <pre><code>public void InsertNewUser(RegisterModel pNewUser, string pEmail)
  {
      // Build rest uri
      string lREST_Uri_Browse = string.Format(@"api/accountapi/saveuserdata"
      // User data
      /*pModelSerialized*/);
  
      // Complete URI
      string lREST_Uri = Helpers_API.endPoint + lREST_Uri_Browse;
  
      var client = new HttpClient();
  
      client.BaseAddress = new Uri(Helpers_API.endPoint);
  
          var newUser = new Models.Models_API.Users
          {
              Email = pNewUser.Email,
              FName = pNewUser.FName,
              LName = pNewUser.LName,
              Inserted = DateTime.Now,
              ActiveAcc = true,
              AccType = pNewUser.AccType,
              BCompanyID = pNewUser.CompanyID,
              PID = pNewUser.PID,
              Password = pNewUser.Password,
              Token = GetToken(pEmail),
              ThirdParty = 0,
              Gender = pNewUser.Gender,
              BirthDate = pNewUser.BirthDate
          };
  
          // Add an Accept header for JSON format.
          //client.DefaultRequestHeaders.Accept.Add(
          //    new MediaTypeWithQualityHeaderValue("application/json"));
          // Create the JSON formatter.
          MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
  
          // Use the JSON formatter to create the content of the request body.
          HttpContent content = new ObjectContent&lt;Models.Models_API.Users&gt;(newUser, jsonFormatter);
  
          var result = client.PostAsync(lREST_Uri_Browse, content).Result;
  }
  </code></pre>
  
  <p>This is the model</p>
  
  <pre><code>public class Users
  {
      public int BrokerID { get; set; }
      public DateTime Inserted { get; set; }
      public string Email { get; set; }
      public string FName { get; set; }
      public string LName { get; set; }
      public bool ActiveAcc { get; set; }
      public int BCompanyID { get; set; }
      public int PID { get; set; }
      public int AccType { get; set; }
      public string Password { get; set; }
      public string Token { get; set; }
      public int Gender { get; set; }
      public DateTime BirthDate { get; set; }
      public int ThirdParty { get; set; }
  }
  </code></pre>
  
  <p>And bellow is the POST in APIController:</p>
  
  <pre><code>public HttpResponseMessage SaveUserData(Users pNewUser)
      {
          bool createUser = false;
          // First check for provided email in DB
          Users existingUser = asigCtx.Users.Where(u =&gt; u.Email == pNewUser.Email).SingleOrDefault();
          if (existingUser == null)
              createUser = true;
          else if (existingUser.ActiveAcc)
              createUser = true;
  
          if (createUser)
          {
              using (asigCtx = new AsigPrimeContext())
              {
                  Users user = new Users()
                  {
                      Email = pNewUser.Email,
                      FName = pNewUser.FName,
                      LName = pNewUser.LName,
                      Inserted = DateTime.Now,
                      ActiveAcc = true,
                      AccType = pNewUser.AccType,
                      BCompanyID = pNewUser.BCompanyID,
                      PID = pNewUser.PID,
                      Password = pNewUser.Password,
                      Token = pNewUser.Token,
                      ThirdParty = 0,
                      Gender = pNewUser.Gender,
                      BirthDate = pNewUser.BirthDate,
                  };
  
                  asigCtx.Users.Add(user);
  
                  asigCtx.SaveChanges();
              }
          }
          var response = Request.CreateResponse&lt;Users&gt;(HttpStatusCode.Created, pNewUser);
          return response;
      }
  </code></pre>
  
  <p>Can anyone give me piece of advice with this code  because i'm new in this and i just want to do it wright. TNX</p>