private static void AwardUser(IUserLogic userLogic, IAwardLogic awardLogic, IUserAwardLogic userAwardLogic) { var useraward = new UserAward(); Console.WriteLine(); try { while (true) { int _userId = ReadInt("Enter the Id of User you want to award: "); if (userLogic.CheckById(_userId)) { useraward.UserId = _userId; break; } else { Console.WriteLine("There's no user with such Id"); } } Console.WriteLine(); while (true) { int _awardId = ReadInt("Enter the Id of Award you want to award with: "); if (awardLogic.CheckById(_awardId)) { useraward.AwardId = _awardId; break; } else { Console.WriteLine("There's no award with such Id"); } } var getUsersWithSameId = userAwardLogic.GetAll().Where(x => x.UserId == useraward.UserId); var getUsersWithSameIdAndSameAward = getUsersWithSameId.Where(x => x.AwardId == useraward.AwardId).Count(); if (getUsersWithSameIdAndSameAward > 0) { Console.WriteLine(); Console.WriteLine("This user already have award with id \"{0}\". He can't get this award twice.", useraward.AwardId); } else { userAwardLogic.Add(useraward); } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } Console.WriteLine(); Init(); }
private static void ShowDetails(IUserLogic userLogic, IAwardLogic awardLogic, IUserAwardLogic userAwardLogic) { Console.WriteLine(); int id = ReadInt("Enter the Id of user: "******"Detailed information about selected user:"******"User Id: {0}", selectedUser.Id); Console.WriteLine("User Name: {0}", selectedUser.Name); Console.WriteLine("User date of birth: {0:D}", selectedUser.DateOfBirth); Console.WriteLine("User age: {0}", selectedUser.Age); Console.WriteLine(); if (userAwardLogic.GetAll().Where(x => x.UserId == selectedUser.Id).Count() == 0) { Console.WriteLine("User \"{0}\" has not any awards.", selectedUser.Name); } else { Console.WriteLine("The awards list of \"{0}\":", selectedUser.Name); foreach (var item in userAwardLogic.GetAll()) { if (item.UserId == selectedUser.Id) { Console.WriteLine(awardLogic.GetById(item.AwardId).Title); } } } } catch (Exception ex) { Console.WriteLine("It's not possible to show any information " + "about awards of selected user because {0}. One of the reasons is " + "that no one of users never get any award. Or may be somebody removed file with " + "information about it.", ex.Message); } Console.WriteLine(); Init(); }