Ejemplo n.º 1
0
 static async void CreateUserBook(AuthorBook obj)
 {
     HttpContent content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json");
     await client.PostAsync("http://localhost:60719/api/UserBooksApi", content);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var menu = "0";

            do
            {
                Task load = LoadProgram();
                load.Wait();
                Console.WriteLine("1> Выдать книгу.");
                Console.WriteLine("2> Вернуть книгу.");
                Console.WriteLine("3> Список должников");
                Console.WriteLine("0> Выход.");
                Console.Write(">");
                menu = Console.ReadLine();

                switch (menu)
                {
                case "1":
                    Console.Clear();
                    AuthorBook authorBook = new AuthorBook();
                    PrintBooks();
                    Console.WriteLine();
                    Console.Write("Введите номер книги (0 - выход): ");
                    int answer = 0;
                    int.TryParse(Console.ReadLine(), out answer);
                    if (answer == 0)
                    {
                        break;
                    }
                    authorBook.BooksId = answer;
                    Console.Clear();
                    PrintUsers();
                    Console.WriteLine();
                    Console.Write("Введите номер пользователя (0 - выход): ");
                    int answer2 = 0;
                    int.TryParse(Console.ReadLine(), out answer2);
                    if (answer2 == 0)
                    {
                        break;
                    }
                    authorBook.UserId     = answer2;
                    authorBook.AuthorId   = books.Find(i => i.Id == authorBook.BooksId).AuthorId;
                    authorBook.AuthorName = books.Find(i => i.Id == authorBook.BooksId).AuthorName;
                    authorBook.UserName   = users.Find(i => i.Id == authorBook.UserId).Name;
                    authorBook.BooksName  = books.Find(i => i.Id == authorBook.BooksId).Title;
                    Console.Clear();
                    Console.Write("Введите количество дней аренды (0 - выход): ");
                    int answer3 = 0;
                    int.TryParse(Console.ReadLine(), out answer3);
                    if (answer3 == 0)
                    {
                        break;
                    }
                    authorBook.DateOrder = DateTime.Now.AddDays(answer3);
                    CreateUserBook(authorBook);
                    Console.Clear();
                    Console.WriteLine("Заказ успешно оформлен!");
                    Console.ReadKey();
                    break;

                case "2":
                    Console.Clear();
                    PrintUsersBooks();
                    Console.WriteLine();
                    Console.Write("Введите номер заказа (0 - выход): ");
                    int answer4 = 0;
                    int.TryParse(Console.ReadLine(), out answer4);
                    if (answer4 == 0)
                    {
                        break;
                    }
                    DeleteUserBook(answer4);
                    Console.Clear();
                    Console.WriteLine("Заказ успешно удален!");
                    Console.ReadKey();
                    break;

                case "3":
                    Console.Clear();
                    PrintUsersBooksDebtor();
                    Console.ReadKey();
                    break;

                default:
                    break;
                }
                Console.Clear();
            } while (!menu.Equals("0"));
        }