public void Delete() { var userGameRepository = new UserGameRepository(Database.Context.Instance); var result = userGameRepository.Delete(new UserGame() { Id = 100 }); Assert.IsNotNull(result); result = userGameRepository.Delete(new UserGame() { Id = -1 }); Assert.IsNull(result); }
public UserDTO Delete(int userId) { Logger.Trace("UserBusiness", "Delete", "Starting the method"); UserDTO result = null; try { var unitOfWork = Database.Context.Instance; var userRepository = new UserRepository(unitOfWork); var userGameRepository = new UserGameRepository(unitOfWork); var user = userRepository.GetById(userId); if (user != null) { userRepository.Delete(user); if (user.Games != null) { foreach (var game in user.Games) { userGameRepository.Delete(game); } } result = UserToUserDTO(user); } } catch (Exception e) { Logger.Error("UserBusiness", "Delete", e.Message); throw e; } finally { Logger.Trace("UserBusiness", "Delete", "Finishing method"); } return(result); }