public IHttpActionResult GetForAuthenticate() { var identity = (ClaimsIdentity)User.Identity; string userId = identity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; int userIdInt = 0; if (!string.IsNullOrEmpty(userId)) { userIdInt = int.Parse(userId); } bool isNew = false; using (var context = new moviedbusersContext()) { if (!context.Users.Any(o => o.Id == int.Parse(userId))) { context.Users.Add(new Users() { Id = userIdInt, UserName = identity.Name }); context.SaveChanges(); isNew = true; } } return(Ok(new { UserId = userIdInt, UserName = identity.Name, NewUser = isNew })); }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid Comment id")); } using (var context = new moviedbusersContext()) { var userComment = context.Comment.Where(r => r.Id == id).FirstOrDefault(); context.Comment.Remove(userComment); context.SaveChanges(); } return(Ok()); }
public List <CommentViewModel> Get(int idMovie) { using (var context = new moviedbusersContext()) { var movieComments = from c in context.Comment join u in context.Users on c.IdUser equals u.Id where c.IdMovie == idMovie select new CommentViewModel { Id = c.Id, Comment = c.Comment1, IdMovie = c.IdMovie, IdUser = c.IdUser, UserName = u.UserName }; return(movieComments.ToList()); } }
public IHttpActionResult Post([FromBody] CommentViewModel commentObj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new moviedbusersContext()) { context.Comment.Add(new Comment() { IdUser = commentObj.IdUser, IdMovie = commentObj.IdMovie, Comment1 = commentObj.Comment, DateCreated = DateTime.Now, DateUpdated = DateTime.Now }); context.SaveChanges(); return(Ok()); } }
public IHttpActionResult Post([FromBody] Rank rankObj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new moviedbusersContext()) { context.Rank.Add(new Rank() { IdUser = rankObj.IdUser, IdMovie = rankObj.IdMovie, Rank1 = rankObj.Rank1, DateCreated = DateTime.Now, DateUpdated = DateTime.Now }); context.SaveChanges(); return(Ok()); } }
public IHttpActionResult PutRank(int id, [FromBody] CommentViewModel commentObj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new moviedbusersContext()) { var userComment = context.Comment.Where(r => r.Id == id).FirstOrDefault(); if (userComment != null) { userComment.Comment1 = commentObj.Comment; userComment.DateUpdated = DateTime.Now; context.SaveChanges(); } else { return(NotFound()); } return(Ok()); } }
public Rank Get(int idUser, int idMovie) { using (var context = new moviedbusersContext()) { return(context.Rank.Where(r => r.IdUser.Equals(idUser) && r.IdMovie.Equals(idMovie)).FirstOrDefault()); } }