public async Task <User> UpdateUser(User user) { try { using (var context = new UserDatabaseEntities1()) { context.Configuration.ProxyCreationEnabled = false; var bdUser = await context.User.FindAsync(user.Id); var userToReturn = new User(); if (bdUser != null) { context.Entry(bdUser).CurrentValues.SetValues(user); await context.SaveChangesAsync(); userToReturn = await context.User.FindAsync(user.Id); } else { userToReturn = null; } return(userToReturn); } } catch (Exception ex) { return(null); } }
public async Task <bool> DeleteUser(Guid userId) { try { using (var context = new UserDatabaseEntities1()) { context.Configuration.ProxyCreationEnabled = false; var bdUser = await context.User.FindAsync(userId); if (bdUser != null) { context.User.Remove(bdUser); await context.SaveChangesAsync(); return(true); } else { return(false); } } } catch (Exception ex) { return(false); } }