예제 #1
0
        private void ShowUsers()
        {
            var users = userLogic.GetAll().ToList();

            if (users.Count == 0)
            {
                ForegroundColor = ConsoleColor.Red;
                WriteLine("The list of Users is empty");
                ResetColor();
            }

            else
            {
                foreach (var item in users)
                {
                    WriteLine();
                    WriteLine($"ID: {item.ID}");
                    WriteLine($"Name: {item.Name}");
                    WriteLine($"Date of birgh: {item.DateOfBirth.ToString("MM/dd/yyyy")}");
                    WriteLine($"Age: {item.Age}");
                    Write("Awards: ");

                    var titles = from awardUser in bindingUserAwardLogic.GetAll(item.ID)
                                 join award in awardLogic.GetAll() on awardUser.AwardID equals award.ID
                                 select(award.Title);

                    foreach (var award in titles)
                    {
                        Write($"{award} ");
                    }
                    WriteLine();
                }
            }
        }
예제 #2
0
        private void ShowAllUser()
        {
            var users = _userLogic.GetAll().ToList();

            if (users.Count == 0)
            {
                Console.WriteLine("base is empty");
            }
            else
            {
                foreach (var item in users)
                {
                    Console.WriteLine("==============================================");
                    Console.WriteLine($"Id: {item.Id}\nUser: {item.Name}\nDate of birgh: {item.DateOfBirth.ToString("MM/dd/yyyy")}\nAge: {item.Age}");
                    Console.Write("Award: ");

                    var titles = from awardUser in _userawardLogic.GetAllAwardUser(item.Id)
                                 join award in _awardLogic.GetAll() on awardUser.AwardId equals award.Id
                                 select(award.Title);

                    foreach (var award in titles)
                    {
                        Console.Write($"{award} ");
                    }
                    Console.WriteLine();
                }
            }
        }
예제 #3
0
        public static void AwardMode()
        {
            while (true)
            {
                ConsoleDisplay.AwardMenuDisplay();
                if (!int.TryParse(Console.ReadLine(), out int input))
                {
                    Console.WriteLine("Incorrect input. Try again!");
                    continue;
                }
                switch (input)
                {
                case 1:
                {
                    Award award = CreateAward();
                    _awardLogic.Add(award);
                    Console.WriteLine("Award added with ID - {0}", award.Id);
                    Console.ReadLine();
                    break;
                }

                case 2:
                {
                    int   id    = GetId();
                    Award award = _awardLogic.GetById(id);
                    ShowAward(award);
                    Console.ReadLine();
                    break;
                }

                case 3:
                {
                    IEnumerable <Award> awards = _awardLogic.GetAll();
                    if (awards.Count() == 0)
                    {
                        Console.WriteLine("Award list is empty.");
                    }
                    else
                    {
                        foreach (var award in awards)
                        {
                            ShowAward(award);
                        }
                    }
                    Console.ReadLine();
                    break;
                }

                case 0:
                default:
                    break;
                }
                if (input == 0)
                {
                    break;
                }
                Console.Clear();
            }
        }
예제 #4
0
        private static void ShowAwards()
        {
            var awards = _awardLogic.GetAll();

            Console.WriteLine("Awards: ");
            foreach (var award in awards)
            {
                Console.WriteLine(award);
            }
        }
예제 #5
0
 private static void ShowAllUsers()
 {
     foreach (var user in userLogic.GetAll())
     {
         Console.WriteLine(user);
         Console.WriteLine("Awards:");
         foreach (var award in awardedUsersLogic.GetAwardsByUserId(user.Id, awardLogic.GetAll()))
         {
             Console.WriteLine($"\t{award}");
         }
     }
 }
예제 #6
0
파일: UI.cs 프로젝트: artemgulai/xt_net_web
        private static void ShowAwards()
        {
            var awards = _awardLogic.GetAll();

            if (awards.Count() == 0)
            {
                Console.WriteLine("No awards in DB.");
                return;
            }

            foreach (var award in _awardLogic.GetAll())
            {
                Console.WriteLine(award);
            }
        }
예제 #7
0
		public ActionResult Details(int id)
		{
			try
			{
				var user = userLogic.Get(id);
				var img = user.ImgId > 0 ? GetImgUrl(user) : null;
				var relatedAwards = user.Awards
					.Select(e => awardLogic.Get(e))
					.Select(e => new AwardModel(e.Title, e.Id))
					.ToList();
				var availableAwards = awardLogic.GetAll().Values
					.Select(e => new AwardModel(e.Title, e.Id))
					.ToList();
				var model = new UserAwardAddingModel(
					user.Id,
					user.Name,
					user.Birthday,
					relatedAwards,
					availableAwards,
					img);
				return View(model);
			}
			catch (KeyNotFoundException)
			{
				return HttpNotFound();
			}
		}
예제 #8
0
 public static void ShowAwards()
 {
     foreach (var award in AwardLogic.GetAll())
     {
         Console.WriteLine(award.ToString());
     }
 }
예제 #9
0
 private static void GetAwards()
 {
     Console.WriteLine("Список наград: ");
     foreach (var award in _awardLogic.GetAll())
     {
         Console.WriteLine(award.ToString());
     }
 }
예제 #10
0
 private static void ShowAwards(IAwardLogic awardLogic)
 {
     Console.WriteLine("Id|Title");
     foreach (var award in awardLogic.GetAll())
     {
         Console.WriteLine(award);
     }
 }
예제 #11
0
 private static void ShowAwards()
 {
     Award[] awards = awardLogic.GetAll();
     Console.WriteLine("List of awards:");
     foreach (var award in awards)
     {
         Console.WriteLine($"ID:{award.Id}; Title - {award.Title}");
     }
 }
예제 #12
0
        public ActionResult GetList()
        {
            var model = awardLogic.GetAll()
                        .Select(e => new AwardModel(
                                    e.Value.Title,
                                    e.Value.Id));

            return(View("AwardList", model));
        }
예제 #13
0
        public static List <Award> ShowAwards()
        {
            List <Award> awards = new List <Award>();

            foreach (var award in awardLogic.GetAll())
            {
                awards.Add(award);
            }
            return(awards);
        }
예제 #14
0
        private static void ShowAwards()
        {
            var awards = awardLogic.GetAll();

            Console.WriteLine("Awards: ");
            foreach (var award in awards)
            {
                Console.WriteLine($"Id: {award.Id}, Name: {award.Name}");
            }
        }
예제 #15
0
        private static void Print(IAwardLogic logic)
        {
            var awards = logic.GetAll();

            int index = 0;

            foreach (var award in awards)
            {
                Console.WriteLine($"Id = {index++}. {award.Title}");
            }
        }
예제 #16
0
 private static void ShowListAwards()
 {
     Award[] awards = awardLogic.GetAll();
     foreach (var award in awards)
     {
         Console.WriteLine($"id: {award.Id} Название: {award.Title}");
     }
     if (awards.Length == 0)
     {
         Console.WriteLine("Спсок пуст");
     }
 }
예제 #17
0
        private void ShowAwards()
        {
            IEnumerable <Award> awards = _awardLogic.GetAll();

            if (awards.Count() != 0)
            {
                foreach (var award in awards)
                {
                    Console.WriteLine(award.ToString());
                }
            }
            else
            {
                Console.WriteLine($"List of awards is empty!{Environment.NewLine}");
            }
        }
예제 #18
0
        private static void ShowAllAwards()
        {
            IEnumerable <Award> awards = _awardLogic.GetAll();

            if (awards.Count() == 0)
            {
                Console.WriteLine("No users.");
            }
            else
            {
                foreach (var award in awards)
                {
                    ShowAward(award);
                }
            }
        }
예제 #19
0
        private static void ShowAwards()
        {
            Award[] awards = awardLogic.GetAll();
            if (!(awards.Length == 0))
            {
                foreach (var award in awards)
                {
                    Console.WriteLine($"{award.Id}. {award.Title}");
                }
            }
            else
            {
                Console.WriteLine("Haven't awards");
            }

            Console.ReadLine();
        }
예제 #20
0
        private static void AwardList()
        {
            var awards = awardLogic.GetAll()
                         .OrderByDescending(x => x.Id);

            if (awards.Count() > 0)
            {
                Console.WriteLine("Awards:");
                foreach (var award in awards)
                {
                    Console.WriteLine($"{award.Id}. {award.Name}");
                }
            }
            else
            {
                Console.WriteLine("There are no awards");
            }
        }
예제 #21
0
        private static void AddAwardsUser(IUserLogic userLogic, IAwardLogic awardLogic)
        {
            Console.Clear();
            Print(userLogic, awardLogic);
            Console.WriteLine("Enter user id: ");
            var  userId = Console.ReadLine();
            var  users  = userLogic.GetAll();
            User user;

            if (int.TryParse(userId, out int id) && id >= 0 && users.Count() - 1 >= id)
            {
                user = users.ElementAt(int.Parse(userId));
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Error: User index does not exist");
                return;
            }

            Print(awardLogic);
            Console.WriteLine("Enter award id: ");
            var awardId = Console.ReadLine();
            var awards  = awardLogic.GetAll();

            if (int.TryParse(awardId, out id) && id >= 0 && awards.Count() - 1 >= id)
            {
                if (userLogic.AddAward(user, id))
                {
                    Console.Clear();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Error: This user already has this award");
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Error: Award index does not exist");
                return;
            }
        }
예제 #22
0
        private static void AwardList()
        {
            StringBuilder sb = new StringBuilder();

            foreach (var entity in awardLogic.GetAll())
            {
                sb.Append(entity);
                sb.Append(Environment.NewLine);
            }

            if (sb.Length == 0)
            {
                System.Console.WriteLine("You have not added awards yet.");
                return;
            }

            System.Console.WriteLine("\tAward-ID, Name");
            System.Console.WriteLine(sb.ToString());
        }
예제 #23
0
        private static void Print(IUserLogic userLogic, IAwardLogic awardLogic)
        {
            var users  = userLogic.GetAll();
            var awards = awardLogic.GetAll();

            int index = 0;

            foreach (var user in users)
            {
                Console.WriteLine($"Id = {index++}. {user.Name} {user.DateOfBirth.ToString("dd/MM/yyyy")}");
                Console.Write($"    Awards: ");
                foreach (var award in user.SetAwards)
                {
                    Console.Write($"{awards.ElementAt(award).Title} ");
                }

                Console.WriteLine();
            }
        }
예제 #24
0
        private static void ShowAwards(IAwardLogic awardLogic)
        {
            Console.WriteLine();
            Console.WriteLine("Id , Title");
            try
            {
                foreach (var award in awardLogic.GetAll())
                {
                    Console.WriteLine($"{award.Id} , {award.Title}");
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("Error: {0}. Before using this option, create at least one award", ex.Message);
            }

            Console.WriteLine();
            Init();
        }
예제 #25
0
 internal List <Award> GetAll()
 {
     return(awardLogic.GetAll());
 }
예제 #26
0
        public static void Run(IUserLogic userLogic, IAwardLogic awardLogic)
        {
            for (; ;)
            {
                Console.Clear();
                Console.WriteLine($"Use commands:\nMode - change data mode\nGetAllUsers - show all users\nUser - show user with current id\nDeleteUser - delete user with current id\nAddUser - add new user");
                Console.WriteLine($"GetAllAwards - show all Awards\nAward - show user with current id\nDeleteAward -delete user with current id\nAddAward - add new user\nExit - quit from application");
                string choose = Console.ReadLine();
                if (choose == "Exit")
                {
                    return;
                }
                switch (choose)
                {
                case "Mode":
                    Console.WriteLine($"Current mode {DataMode.GetLogic("DataMode")} will changed");
                    DataMode.SwitchLogic("DataMode");
                    Console.WriteLine($"New mode {DataMode.GetLogic("DataMode")}. This mode will work after restart of application");
                    Console.ReadKey();
                    break;

                case "GetAllUsers":
                    foreach (var item in userLogic.GetAll())
                    {
                        Console.WriteLine(item);
                    }
                    Console.ReadKey();
                    break;

                case "GetAllAwards":
                    foreach (var item in awardLogic.GetAll())
                    {
                        Console.WriteLine(item);
                    }
                    Console.ReadKey();
                    break;

                case "User":
                    Console.WriteLine("Enter user id");
                    uint.TryParse(Console.ReadLine(), out _userId);
                    Console.WriteLine(userLogic.GetById(_userId));
                    if (userLogic.GetUserAwards(_userId).Any())
                    {
                        Console.WriteLine("Awards:");
                        foreach (uint item in userLogic.GetUserAwards(_userId))
                        {
                            Console.WriteLine(awardLogic.GetById(item));
                        }
                    }
                    Console.ReadKey();
                    break;

                case "Award":
                    Console.WriteLine("Enter award id");
                    uint.TryParse(Console.ReadLine(), out _awardId);
                    Console.WriteLine(awardLogic.GetById(_awardId));
                    Console.ReadKey();
                    break;

                case "DeleteUser":
                    Console.WriteLine("Enter user id");
                    uint.TryParse(Console.ReadLine(), out _userId);
                    if (userLogic.DeleteById(_userId))
                    {
                        Console.WriteLine($"User with id = {_userId} deleted successfully!");
                    }
                    else
                    {
                        Console.WriteLine($"Can't delete user with id = {_userId}!");
                    }
                    Console.ReadKey();
                    break;

                case "DeleteAward":
                    Console.WriteLine("Enter award id");
                    uint.TryParse(Console.ReadLine(), out _awardId);
                    if (awardLogic.DeleteById(_awardId))
                    {
                        Console.WriteLine($"Award with id = {_awardId} deleted successfully!");
                    }
                    else
                    {
                        Console.WriteLine($"Can't delete award with id = {_awardId}!");
                    }
                    Console.ReadKey();
                    break;

                case "AddUser":
                    Console.WriteLine("Enter new user name");
                    string _newUserName = Console.ReadLine();
                    Console.WriteLine("Enter new user birthday");
                    DateTime.TryParse(Console.ReadLine(), out DateTime _userBirthday);
                    if (userLogic.Add(new User()
                    {
                        Name = _newUserName, DateOfBirth = _userBirthday
                    }))
                    {
                        Console.WriteLine("User added successfully!");
                    }
                    else
                    {
                        Console.WriteLine("Can't create new user!");
                    }
                    Console.ReadKey();
                    break;

                case "AddAward":
                    Console.WriteLine("Enter new award name");
                    string _newAwardName = Console.ReadLine();
                    if (awardLogic.Add(new Award()
                    {
                        Name = _newAwardName
                    }))
                    {
                        Console.WriteLine("Award added successfully!");
                    }
                    else
                    {
                        Console.WriteLine("Can't create new award!");
                    }
                    Console.ReadKey();
                    break;

                default:
                    break;
                }
            }
        }
예제 #27
0
        private static bool ProcessInput()
        {
            string command = ReadInput();

            string[] commandArgs = command.Split(separator,
                                                 StringSplitOptions.RemoveEmptyEntries);

            switch (commandArgs[0].ToLower())
            {
            case "add":
                switch (commandArgs[1].ToLower())
                {
                case "user":
                    userLogic.Add(new User()
                    {
                        Name        = ReadInput("Name"),
                        DateOfBirth = DateTime.Parse(ReadInput("Date of birth"))
                    });
                    break;

                case "award":
                    awardLogic.Add(new Award()
                    {
                        Title = ReadInput("Title")
                    });
                    break;

                default:
                    WriteLine("Usage: add <user/award>");
                    break;
                }
                break;

            case "remove":
                switch (commandArgs[1].ToLower())
                {
                case "user":
                    userLogic.Remove(int.Parse(commandArgs[2]));
                    break;

                case "award":
                    awardLogic.Remove(int.Parse(commandArgs[2]));
                    break;

                default:
                    WriteLine("Usage: remove <user/award>");
                    break;
                }
                break;

            case "list":
                switch (commandArgs[1].ToLower())
                {
                case "users":
                    foreach (var entry in userLogic.GetAll())
                    {
                        WriteLine(entry.ToString());
                        foreach (var award in userLogic.GetAwardsFor(entry.Id, awardLogic))
                        {
                            Write(" - ");
                            WriteLine(award.ToString());
                        }
                    }
                    break;

                case "awards":
                    foreach (var entry in awardLogic.GetAll())
                    {
                        WriteLine(entry.ToString());
                    }
                    break;

                default:
                    WriteLine("Usage: list <users/awards>");
                    break;
                }
                break;

            case "award":
                switch (commandArgs[1].ToLower())
                {
                case "assign":
                    userLogic.AddAward(int.Parse(commandArgs[2]),
                                       awardLogic.GetById(int.Parse(commandArgs[3])));
                    break;

                case "revoke":
                    userLogic.RemoveAward(int.Parse(commandArgs[2]),
                                          awardLogic.GetById(int.Parse(commandArgs[3])));
                    break;

                default:
                    WriteLine("Usage: award <assign/revoke> (userId) (awardId)");
                    break;
                }
                break;

            case "exit":
                return(false);
            }
            return(true);
        }
예제 #28
0
 static AwardService()
 {
     _awardLogic = Task06.MyDB.IoC.DependencyResolver.AwardLogic;
     _sb         = new StringBuilder();
     _awards     = _awardLogic.GetAll();
 }
예제 #29
0
 public static IEnumerable <Award> GetAllAwards()
 {
     return(_awardLogic.GetAll());
 }
예제 #30
0
        public static void Interaction()
        {
            string input;
            string name;
            string dateOfBirth;
            string title;

            while (true)
            {
                Console.WriteLine("1 - Add a new user");
                Console.WriteLine("2 - Delete user");
                Console.WriteLine("3 - Get all users");
                Console.WriteLine("4 - Add a new award");
                Console.WriteLine("5 - Delete award");
                Console.WriteLine("6 - Get all awards");
                Console.WriteLine("7 - Give an user an award");
                Console.WriteLine("0 - Exit");
                Console.WriteLine(string.Empty);
                Console.Write(">>");

                input = Console.ReadLine();

                if (input == "1")
                {
                    Console.WriteLine("Your name can contain only letters and digits and be not longer than 15 symbols");
                    Console.WriteLine("Enter your name: ");

                    name = Console.ReadLine();

                    Console.WriteLine("Enter your date fo birth in format DD/MM/YYYY: ");
                    dateOfBirth = Console.ReadLine();

                    try
                    {
                        userLogic.Add(name, dateOfBirth, null);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (input == "2")
                {
                    Console.WriteLine("Enter id you want to delete: ");

                    if (int.TryParse(Console.ReadLine(), out int id))
                    {
                        if (id >= 0)
                        {
                            userLogic.Delete(id);
                            Console.WriteLine("Deleting is successful");
                        }
                        else
                        {
                            Console.WriteLine("Id cannot be less than 0");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You have to enter id correctly");
                    }
                }
                else if (input == "3")
                {
                    foreach (var user in userLogic.GetAll())
                    {
                        Console.Write(user);

                        foreach (var award in userAndAwardLogic.GetAll(user.Id))
                        {
                            Console.Write($" {award}");
                        }

                        Console.WriteLine();
                    }
                }
                else if (input == "4")
                {
                    Console.WriteLine("A title can contain only letters and digits and be not longer than 15 symbols");
                    Console.WriteLine("Enter a title: ");

                    title = Console.ReadLine();

                    try
                    {
                        awardLogic.Add(title, null);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (input == "5")
                {
                    Console.WriteLine("Enter id you want to delete: ");

                    if (int.TryParse(Console.ReadLine(), out int id))
                    {
                        if (id >= 0)
                        {
                            awardLogic.Delete(id, true);
                            Console.WriteLine("Deleting is successful");
                        }
                        else
                        {
                            Console.WriteLine("Id cannot be less than 0");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You have to enter id correctly");
                    }
                }
                else if (input == "6")
                {
                    foreach (var award in awardLogic.GetAll())
                    {
                        Console.WriteLine(award);
                    }
                }
                else if (input == "7")
                {
                    Console.WriteLine("Enter an id of user you want to award");
                    if (int.TryParse(Console.ReadLine(), out int userId))
                    {
                        Console.WriteLine("Enter an id of award you want to award");
                        if (int.TryParse(Console.ReadLine(), out int awardId))
                        {
                            try
                            {
                                userAndAwardLogic.Add(userId, awardId);
                                Console.WriteLine("Success!");
                            }
                            catch (ArgumentException e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                        else
                        {
                            Console.WriteLine("You have to enter award id correctly");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You have to enter user id correctly");
                    }
                }
                else if (input == "0")
                {
                    Console.WriteLine("Good luck!");
                    break;
                }
                else
                {
                    Console.WriteLine("You entered incorrect data");
                }

                Console.WriteLine();
            }
        }