public async Task <IActionResult> RemoveComment(int CommentId, [Bind("AnimalId")] AnimalComment animal) { AnimalComment commentary = (from c in _context.AnimalComment select c).Where(c => c.CommentId.Equals(CommentId)).First(); _context.Remove(commentary); await _context.SaveChangesAsync(); Animal fAnimal = await _context.Animals.FindAsync(animal.AnimalId); var rqf = _httpContextAccessor.HttpContext.Features.Get <IRequestCultureFeature>(); var culture = rqf.RequestCulture.Culture; var breedsSet = _context.AnimalBreeds; var speciesSet = _context.AnimalSpecies; var commentsSet = from c in _context.AnimalComment select c; commentsSet = commentsSet.Where(s => s.AnimalId.Equals(fAnimal.AnimalId)); foreach (AnimalComment com in commentsSet) { var user = _context.Users.Where(u => u.Id.Equals(com.UserId)).First(); com.SetEmail(user.Email); com.SetUserName(user.Name); com.SetUserImage(user.ImageURL); } var vs = new AnimalViewModel(fAnimal, culture, speciesSet, breedsSet, commentsSet); return(View("Details", vs)); }
public async Task <IActionResult> Edit(int id, [Bind("CommentId,AnimalId,UserId,Commentary")] AnimalComment animalComment) { if (id != animalComment.CommentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(animalComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnimalCommentExists(animalComment.CommentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(animalComment)); }
public async Task <IActionResult> Create([Bind("CommentId,AnimalId,UserId,Commentary")] AnimalComment animalComment) { if (ModelState.IsValid) { _context.Add(animalComment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(animalComment)); }
public async Task <IActionResult> AddComment(string Commentary, [Bind("AnimalId,Commentary")] AnimalComment animal) { User currentUser = (from u in _context.Users select u).Where(s => s.Email.Equals(User.Identity.Name)).First(); AnimalComment comment = new AnimalComment(); comment.AnimalId = animal.AnimalId; comment.UserId = currentUser.Id; comment.Commentary = Commentary; comment.InsertDate = DateTime.Now; _context.Add(comment); await _context.SaveChangesAsync(); Animal fAnimal = await _context.Animals.FindAsync(animal.AnimalId); var rqf = _httpContextAccessor.HttpContext.Features.Get <IRequestCultureFeature>(); var culture = rqf.RequestCulture.Culture; var breedsSet = _context.AnimalBreeds; var speciesSet = _context.AnimalSpecies; var commentsSet = from c in _context.AnimalComment select c; commentsSet = commentsSet.Where(s => s.AnimalId.Equals(fAnimal.AnimalId)); foreach (AnimalComment com in commentsSet) { var user = _context.Users.Where(u => u.Id.Equals(com.UserId)).First(); com.SetEmail(user.Email); com.SetUserName(user.Name); com.SetUserImage(user.ImageURL); } var vs = new AnimalViewModel(fAnimal, culture, speciesSet, breedsSet, commentsSet); return(View("Details", vs)); }