public IHttpActionResult PostRegistration(Login data, object role) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} //Login user = new Login(); //db.Login.Add(data); //db.SaveChanges(); return Ok(); }
public IHttpActionResult PostRegistration(Login data) { var user = new { username = data.username, role = new { Title = data.role_Title, bitMask = data.role_bitMask } }; //db.Logins.Add(data); //db.SaveChanges(); //var resp = new HttpResponseMessage(); //resp.Content = new ObjectContent<object>(user, new JsonMediaTypeFormatter(), "application/json"); var nvc = new NameValueCollection(); nvc["username"] = user.username; nvc["Title"] = user.role.Title; nvc["bitMask"] = user.role.bitMask; var resp = Request.CreateResponse<NameValueCollection>(HttpStatusCode.OK, nvc); return ResponseMessage(resp); string user1 = "user"; string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(user1); var cookie = new CookieHeaderValue("user", user1); cookie.Expires = DateTimeOffset.Now.AddDays(1); cookie.Domain = null; cookie.Path = "/"; resp.Headers.AddCookies(new CookieHeaderValue[] { cookie }); //resp.Headers.Add("Content-Type", "application/json"); resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); //return ResponseMessage(resp); //return resp; }