public IActionResult Post([FromBody] MediaUser review) { try { string bearer = HttpContext.Request.Headers["Authorization"]; string token = bearer.Split(" ")[1]; int userId = Int16.Parse(TokenService.GetUserFromToken(token)); var newReview = new MediaUser(); newReview.UserId = userId; newReview.MediaId = review.MediaId; newReview.Review = review.Review; newReview.Liked = review.Liked; _db.Add(newReview); _db.SaveChanges(); return(Ok(newReview)); } catch (Exception e) { var responseFail = new ErrorResponse(); responseFail.StatusCode = 500; responseFail.Message = e.Message; return(StatusCode(500, responseFail)); } }
// protection for other websites using this post endpoints public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); if (user == null) { user = new MediaUser { Id = Guid.NewGuid().ToString(), UserName = model.UserName, Role = "Gebruiker" }; var identityResult = await _userManager.CreateAsync(user, model.Password); if (identityResult.Succeeded) { return(View("Success")); } return(View()); } } return(View()); }
public void AddRating(MediaRatingInputModel model) { try { var obj = new MediaUser { Grade = model.Rating, MediaID = model.MediaID, UserID = model.UserID }; _context.MediaUsers.Add(obj); _context.SaveChanges(); return; } catch { return; } }
public void InsertMediaUser(MediaUser MediaUser) { context.MediaUsers.Add(MediaUser); }