public MovieCommentResponse update(int commentId, MovieCommentRequest request) { var originalModel = _context.movieComments.FirstOrDefault(m => m.id.Equals(commentId)); var parsedModel = new MovieComment { description = request.description, updatedAt = request.updatedAt }; if (originalModel is null) { throw new Exception("Model not found"); } originalModel.description = parsedModel.description; _context.movieComments.Update(originalModel); _context.SaveChanges(); return(new MovieCommentResponse { id = originalModel.id, createdAt = originalModel.createdAt, description = originalModel.description, movieId = originalModel.movieId, updatedAt = originalModel.updatedAt, userId = originalModel.userId }); }
public void Post([FromBody] MovieComment model) { if (model != null) { MoviesDBContext.comments.Add(model); } }
public async Task <ActionResult <MovieComment> > PostMovieComment(MovieComment movieComment) { _context.MovieComment.Add(movieComment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMovieComment", new { id = movieComment.MovieCommentId }, movieComment)); }
public async Task <IActionResult> OnGetDeleteAsync(int?id) { if (id == null) { return(Page()); } _client.BaseAddress = new Uri(_apiUrl); _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Add("x-apikey", _apiKey); try { string json; HttpResponseMessage response; response = await _client.DeleteAsync("moviereview/api/moviecomments/" + id); Console.WriteLine($"status from POST {response.StatusCode}"); response.EnsureSuccessStatusCode(); Console.WriteLine($"added resource at {response.Headers.Location}"); json = await response.Content.ReadAsStringAsync(); MovieComment _m = JsonConvert.DeserializeObject <MovieComment>(json); TempData["successmsg"] = "Comment has been deleted Successfully"; return(RedirectToPage(new { id = _m.MovieId })); } catch (Exception e) { TempData["errormsg"] = e.Message; return(RedirectToPage("/Index")); } }
public void Update(string comment, int id) { MovieComment movieComment = MovieCommentRepository.GetById(id); movieComment.Comment = comment; MovieCommentRepository.Update(movieComment); }
public MovieComment Add(string content, int movieId, string userId) { if (string.IsNullOrWhiteSpace(content) || string.IsNullOrWhiteSpace(userId)) { return(null); } var user = this.users.GetById(userId); if (user == null) { return(null); } var comment = new MovieComment() { Content = content, MovieId = movieId, AuthorId = user.Id }; this.movieComments.Add(comment); this.movieComments.SaveChanges(); return(this.movieComments.GetById(comment.Id)); }
public async Task <IActionResult> PutMovieComment(int id, MovieComment movieComment) { if (id != movieComment.MovieCommentId) { return(BadRequest()); } _context.Entry(movieComment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieCommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Approve(int id) { MovieComment comment = MovieCommentRepository.GetById(id); comment.IsAproved = true; MovieCommentRepository.Update(comment); }
public static MovieCommentMainDTO MovieCommentToMainDTO(MovieComment movieComment) { return(new MovieCommentMainDTO() { Id = movieComment.Id, Comment = movieComment.Comment, User = UserToUserMainDTO(movieComment.User) }); }
private static MovieCommentModel ConvertToMovieCommentModel(MovieComment movieComment) { return(new MovieCommentModel { Comment = movieComment.Comment, DateCreated = movieComment.DateCreated, Username = movieComment.User.Username }); }
public static ApprovalOverviewDTO MovieCommentToApprovalDTO(MovieComment movieComment) { return(new ApprovalOverviewDTO() { Id = movieComment.Id, UserId = movieComment.UserId, UserFullName = movieComment.User.FirstName + ' ' + movieComment.User.LastName, Comment = movieComment.Comment }); }
public async Task <MovieComment> CreateMovieComment(string movieId, Comment comment) { MovieComment movieComment = new MovieComment(); movieComment.MovieId = movieId; movieComment.CommentId = comment.CommentId; await MovieComments.InsertOneAsync(movieComment); return(movieComment); }
public void UpdateMovieComment(MovieComment model) { MovieComment movieComment = context.MovieComments.SingleOrDefault(u => u.Id == model.Id); if (movieComment != null) { context.Entry(movieComment).CurrentValues.SetValues(model); context.SaveChangesAsync(); } }
public void Delete(int id) { MovieComment movieComment = new MovieComment { Id = id, }; Context.MovieComments.Remove(movieComment); Context.SaveChanges(); }
public static MovieCommentsModel ConvertToMovieCommentsModel(MovieComment movieComment) { return(new MovieCommentsModel { Comment = movieComment.Comment, DaysAgo = DateTime.Now.Subtract(movieComment.DateCreated).Days, Username = movieComment.User.UserName, IsApproved = movieComment.IsAproved, }); }
public static ModifyCommentModel ConvertToModifyCommentsModel(MovieComment movieComment) { return(new ModifyCommentModel { Id = movieComment.Id, Comment = movieComment.Comment, DateCreated = movieComment.DateCreated, Username = movieComment.User.UserName, IsApproved = movieComment.IsAproved, }); }
public void Add(string comment, int movieId, int userId) { var movieComment = new MovieComment(); movieComment.Comment = comment; movieComment.MovieId = movieId; movieComment.UserId = userId; movieComment.DateCreated = DateTime.Now; MovieCommentRepository.Add(movieComment); }
public string AddComment(MovieComment comment) { if (ModelState.IsValid) { blogService.InsertBlogComment(comment); return("Thank you for your comment"); } else { return("Error"); } }
public LocalRedirectResult NewMComment(int Movieid, string text) { var user = _userManager.GetUserName(HttpContext.User); var comment = new MovieComment { Id = _context.MComments.Max(s => s.Id) + 1, MId = (int)Movieid, Creator = user, Text = text }; _context.MComments.Add(comment); _context.SaveChanges(); return(LocalRedirect("/Movies/Details/" + Movieid)); }
public BlogViewModel( Movie blog, MovieComment blogComment, List <MovieComment> blogComments, List <MovieCategory> categories, List <Anonymous> popularTags, List <Archive> archives, PreNextBlog preNextBlog) { Blog = blog; BlogComments = blogComments; BlogComment = blogComment; Categories = categories; PopularTags = popularTags; Archives = archives; PreNextBlog = preNextBlog; }
public MovieForm(Movie movieModel, User userModel) { InitializeComponent(); movie = movieModel; user = userModel; this.Text = $"{this.Text} - {movie.Title}"; this.AcceptButton = saveMovieButton; movieComment = GlobalConfig.Connection.FindMovieComment(movie, user); if (movieComment != null) { movieCommentTextBox.Text = movieComment.Comment; saveMovieButton.Text = "Update"; } }
private void InitializeFields() { this.user = new CinemaWorldUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", }; this.firstDirector = new Director { Id = 1, FirstName = "Kiril", LastName = "Petrov", }; this.firstMovie = new Movie { Id = 1, Name = "Avatar", DateOfRelease = DateTime.UtcNow, Resolution = "HD", Rating = 7.80m, Description = "Avatar movie description", Language = "English", CoverPath = TestCoverPath, WallpaperPath = TestWallpaperPath, TrailerPath = TestTrailerPath, CinemaCategory = CinemaCategory.A, Length = 120, DirectorId = this.firstDirector.Id, }; this.firstMovieComment = new MovieComment { MovieId = this.firstMovie.Id, Content = "Test comment here", UserId = this.user.Id, }; }
public ActionResult AddComment(MovieComment blogComment, string CaptchaCode) { try { if (Session["Captcha"] != null && Session["Captcha"].ToString() == CaptchaCode) { bs.InsertBlogComment(blogComment); return(Json(new { code = 1 }, JsonRequestBehavior.AllowGet)); } return(Json(new { code = -1 }, JsonRequestBehavior.AllowGet)); throw new Exception(); } catch (Exception e) { throw; } }
public async Task OnGetAsync(int?id) { if (HttpContext.Session.IsAvailable) { var userString = HttpContext.Session.GetString("userString"); if (userString == null) { Console.WriteLine("User is not loggedIn"); } else { _loggedInUser = JsonConvert.DeserializeObject <User>(HttpContext.Session.GetString("userString")); } } _client.BaseAddress = new Uri(_apiUrl); _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Add("x-apikey", _apiKey); try { string json; HttpResponseMessage response; // get the specified item response = await _client.GetAsync("moviereview/api/MovieComments/" + id); if (response.IsSuccessStatusCode) { movieComment = await response.Content.ReadAsAsync <MovieComment>(); } else { Console.WriteLine("Internal Server error"); } // return RedirectToPage("/Movies/View", new { id = movieComment.MovieId }); } catch (Exception e) { Console.WriteLine(e.Message); } }
public MovieCommentResponse create(int movieId, MovieCommentRequest request) { var newModel = new MovieComment { movieId = movieId, description = request.description, userId = request.userId, }; _context.movieComments.Add(newModel); _context.SaveChanges(); return(new MovieCommentResponse { id = newModel.id, createdAt = newModel.createdAt, description = newModel.description, movieId = movieId, updatedAt = newModel.updatedAt, userId = newModel.userId }); }
private void SaveMovieButton_Click(object sender, EventArgs e) { if (movieComment == null) { MovieComment mc = new MovieComment() { MovieId = movie.Id, Movie = movie, UserId = user.Id, User = user, Comment = movieCommentTextBox.Text }; GlobalConfig.Connection.AddMovieComment(mc); Helpers.ShowMessageBox("AddMovieComment"); } else { movieComment.Comment = movieCommentTextBox.Text; GlobalConfig.Connection.UpdateMovieComment(movieComment); Helpers.ShowMessageBox("UpdateMovieComment"); } }
public ActionResult CommentSubmit([Bind(Include = "ID,Content,score,UserID,MovieID")] MovieComment comment) { comment.CommentTime = DateTime.Now; comment.User = userManage.Find(comment.UserID); int isUser = commentMange.Count(p => p.UserID == comment.UserID && p.MovieID == comment.MovieID); if (isUser > 0) { return(Content("<h1 class='text-center' style='color:#fff;'>您已评论过此电影!</h1>")); } if (ModelState.IsValid) { commentMange.Add(comment); comment.User.SweetScore = comment.User.SweetScore++; userManage.Update(comment.User); var _comment = commentMange.FindList(p => p.MovieID == comment.MovieID); _comment = _comment.OrderBy(p => p.CommentTime); const int pageSize = 5; return(PartialView("CommentList", _comment.ToPagedList(1, pageSize))); } return(Content("<h1 class='text-center' style='color:#fff;'>评论失败</h1>")); }
public async Task <IActionResult> Create([Bind("CommentId,Content,Rating")] Comment comment, [Bind("movieId")] int movieId) { if (ModelState.IsValid) { if (HttpContext.Session.GetInt32("token") != null) { int userId = (Int32)HttpContext.Session.GetInt32("token"); comment.UserId = userId; } _context.Add(comment); await _context.SaveChangesAsync(); MovieComment movieComment = new MovieComment(); movieComment.CommentId = comment.CommentId; movieComment.MovieId = movieId; _context.MovieComment.Add(movieComment); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "PlayMovie", new { id = movieId })); } return(View(comment)); }
public async Task CreateAsync(int movieId, string userId, string content, int?parentId = null) { var movieComment = new MovieComment { MovieId = movieId, UserId = userId, Content = content, ParentId = parentId, }; bool doesMovieCommentExist = await this.commentsRepository .All() .AnyAsync(x => x.MovieId == movieComment.MovieId && x.UserId == userId && x.Content == content); if (doesMovieCommentExist) { throw new ArgumentException( string.Format(ExceptionMessages.MovieCommentAlreadyExists, movieComment.MovieId, movieComment.Content)); } await this.commentsRepository.AddAsync(movieComment); await this.commentsRepository.SaveChangesAsync(); }
public ActionResult Modify(int ID, [Bind(Include = "ID,UserID,MovieID,Content,CommentTime,Score,Likes")] MovieComment movieComment) { Response _resp = new DAL.Response(); var _comment = commentManage.Find(ID); if (ModelState.IsValid) { if (_comment == null) { _resp.Code = 0; _resp.Message = "该评论不存在,可能遭到删除"; } else { _resp = commentManage.Update(movieComment); } } else { _resp.Code = 0; _resp.Message = General.GetModelErrorString(ModelState); } return(Json(_resp)); }