public async Task ChangePostStatus(int id, PostStatus newStatus) { var entity = new Post { Id = id, Status = newStatus }; _context.Attach(entity); _context.Entry(entity).Property(x => x.Status).IsModified = true; await _context.SaveChangesAsync(); }
public async Task ChangeUserAdminStatus(int userId, bool isAdmin) { var entity = new User { Id = userId, IsAdmin = isAdmin, DetailsStamp = Guid.NewGuid().ToString() }; _context.Attach(entity); _context.Entry(entity).Property(x => x.IsAdmin).IsModified = true; _context.Entry(entity).Property(x => x.DetailsStamp).IsModified = true; await _context.SaveChangesAsync(); }
public void Adiciona(Post post, Usuario usuario) { contexto.Attach(usuario); post.Autor = usuario; contexto.Posts.Add(post); contexto.SaveChanges(); }
public bool Edit(T entity) { if (entity == null) { return(false); } blogContext.Attach(entity); blogContext.Entry(entity).State = EntityState.Modified; return(UnitWork.SaveChanges() > 0); }
public async Task LogOff(string token) { var entity = new UserToken { Token = token }; BlogContext.Attach(entity).State = EntityState.Deleted; await BlogContext.SaveChangesAsync(); BlogContext.RemoveUserTokenCache(); }