/*public UserModel getUser(int userId) * { * return _context.UserModel.Where(item => item.Id == userId).FirstOrDefault(); * } * * public HistoryModel getHistory(int userId) * { * return _context.HistoryModel.Where(item => item.User.Id == userId).FirstOrDefault(); * } * * public IEnumerable<Friend> getFriends(int userId) * { * return _context.Friend.Where(item => item.Me.Id == userId).ToList(); * } * * public APIReturnObject addFriend(int userId, int friendId) * { * FriendEntity newFriend = new FriendEntity(_viewUser.getUserById(userId), _viewUser.getUserById(friendId)); * ReturnObject returnObject = _manageUser.addFriend(newFriend); * if (returnObject.isSuccess()) * { * _context.Friend.Add(_friendBridge.mapToFriendFrom(newFriend)); * _context.SaveChanges(); * } * return _returnBridge.mapToAPIReturnObjectFrom(returnObject); * } * * public APIReturnObject removeFriend(int userId, int friendId) * { * FriendEntity friend = _viewUser.getFriendById(friendId); * ReturnObject returnObject = _manageUser.removeFriend(friend); * if (returnObject.isSuccess()) * { * _context.Friend.Remove(_friendBridge.mapToFriendFrom(friend)); * _context.SaveChanges(); * } * return _returnBridge.mapToAPIReturnObjectFrom(returnObject); * } * * public APIReturnObject updateHistory(int userId, int numberOfPenalties) * { * UserEntity user = _viewUser.getUserById(userId); * HistoryEntity history = _viewUser.getHistory(); * ReturnObject returnObject = _manageUser.updateHistory(history); * if (returnObject.isSuccess()) * { * _context.HistoryModel.Where(item => item.User.Id == userId).FirstOrDefault().NumberOfPenalties = (history.NumberOfPenalties + numberOfPenalties); * _context.HistoryModel.Where(item => item.User.Id == userId).FirstOrDefault().PlayedGames = (history.PlayedGames + 1); * _context.Entry(_bridge.mapToUserFrom(user)).State = Microsoft.EntityFrameworkCore.EntityState.Modified; * _context.SaveChanges(); * } * return _returnBridge.mapToAPIReturnObjectFrom(returnObject); * } * * public APIReturnObject changeUserstatus(int userId, Status newStatus) * { * UserEntity user = _viewUser.getUserById(userId); * ReturnObject returnObject = _manageUser.changeUserStatus(newStatus); * if (returnObject.isSuccess()) * { * _context.UserModel.Where(item => item.Id == userId).FirstOrDefault().ActualStatus = _bridge.mapToUserstatusFrom(newStatus); * _context.Entry(_bridge.mapToUserFrom(user)).State = Microsoft.EntityFrameworkCore.EntityState.Modified; * _context.SaveChanges(); * } * return _returnBridge.mapToAPIReturnObjectFrom(returnObject); * }*/ public ReturnObject create(int id, string name, string email, string password) { UserModel newUser = _bridge.mapToUserFrom(new UserEntity(id, email, name, password)); if (_context.UserModel.Where(item => item.Id == newUser.Id).Count() < 1) { _context.UserModel.Add(newUser); _context.SaveChanges(); return(new ReturnObject(true, "User created")); } return(new ReturnObject(false, "User already exists.")); }
public async Task <ActionResult <UserModel> > GetUser(int userId) { if (_userservice.findById(userId) == null) { return(NotFound("User not Found.")); } return(await Task.FromResult(_userBridge.mapToUserFrom(_userservice.findById(userId)))); }