public ActionResult Edit([Bind(Include = "Id,Name,Age,Description,PetType")] Pet pet) { if (ModelState.IsValid) { db.Entry(pet).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pet)); }
public async Task <Comment> Get(int id) { var comment = await _context.Comments.Select(x => new Comment { PetId = x.PetId, Id = x.Id, Rate = x.Rate, Message = x.Message, UserId = x.UserId, User = new ApplicationUser { Name = x.User.Name, Surname = x.User.Surname } } ).Where(x => x.Id == id).FirstOrDefaultAsync(); _context.Entry(comment).State = EntityState.Detached; return(comment); }
public async Task <bool> UserCanEdit(string userEmail, int commentId) { ApplicationUser user = await _userManager.FindByEmailAsync(userEmail); if (user == null) { return(false); } bool isAdmin = await _userManager.IsInRoleAsync(user, ApplicationUserService.ROLE_ADMIN); Comment comment = await Get(commentId); _context.Entry(comment).State = EntityState.Detached; if (comment == null) { //Si no existe devuelvo true asi no da error de login, luego HasCorrectData detecta que no existe return(true); } return(comment.UserId == user.Id || isAdmin); }