public IHttpActionResult PostComment(tempComment comment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var addedComment = new Comment(); string id; id = User.Identity.GetUserId(); id = RequestContext.Principal.Identity.GetUserId(); var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db)); var currentUser = manager.FindById(id); addedComment.Author = currentUser; addedComment.Content = comment.Content; addedComment.DateTime = DateTime.Now; if (comment.Rating < 1) comment.Rating = 1; else if (comment.Rating > 5) comment.Rating = 5; addedComment.Rating = comment.Rating; var currentEstablishment = from estbl in db.Establishments where estbl.Id == comment.EstablishmentId select estbl; var final_establishment = currentEstablishment.Single(); addedComment.Establishment = final_establishment; db.Comments.Add(addedComment); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment); }
public IHttpActionResult PostComment(tempComment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var addedComment = new Comment(); string id; id = User.Identity.GetUserId(); id = RequestContext.Principal.Identity.GetUserId(); var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var currentUser = manager.FindById(id); addedComment.Author = currentUser; addedComment.Content = comment.Content; addedComment.DateTime = DateTime.Now; if (comment.Rating < 1) { comment.Rating = 1; } else if (comment.Rating > 5) { comment.Rating = 5; } addedComment.Rating = comment.Rating; var currentEstablishment = from estbl in db.Establishments where estbl.Id == comment.EstablishmentId select estbl; var final_establishment = currentEstablishment.Single(); addedComment.Establishment = final_establishment; db.Comments.Add(addedComment); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment)); }