Exemplo n.º 1
0
        public static async Task CountCustomersAsync()
        {
            using var context = new CegidDbContext();

            var query = context.Customers
                        .Where(c => c.IsEnabled);

            WriteLine($"Customers: {await query.CountAsync()}");
        }
Exemplo n.º 2
0
        public static async Task CreateCustomerAsync()
        {
            Write("First name: ");
            var firstName = ReadLine();

            Write("Last name: ");
            var lastName = ReadLine();

            var customer = new Customer
            {
                FirstName = firstName,
                LastName  = lastName
            };

            WriteLine($"Creation of \n{customer}");

            using var context = new CegidDbContext();
            context.Add(customer);
            await context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public static async Task ListCustomersAsync()
        {
            using var context = new CegidDbContext();

            var query = context.Customers
                        .Where(c => c.IsEnabled);

            WriteLine("Number of clients to take:");
            var take = int.Parse(ReadLine());

            query = query.Take(take);

            WriteLine("Number of clients to skip:");
            var skip = int.Parse(ReadLine());

            query = query.Skip(skip);

            foreach (var customer in await query.ToListAsync())
            {
                WriteLine(customer);
            }
        }
Exemplo n.º 4
0
 public static async Task CreateRoomsAsync()
 {
     using var context = new CegidDbContext();
     if (await context.Rooms.AnyAsync())
     {
         WriteLine("Already created.");
         return;
     }
     for (int floor = 0; floor < 6; floor++)
     {
         for (int n = 0; n < 10; n++)
         {
             var room = new Room
             {
                 Number = floor * 100 + n,
                 Floor  = floor
             };
             context.Add(room);
         }
     }
     await context.SaveChangesAsync();
 }
Exemplo n.º 5
0
        public static async Task CreateReservationAsync()
        {
            Write("Customer id:");
            var customerId = ReadLine();

            DateTime start;

            do
            {
                Write("Start date (dd/mm/yyyy):");
            } while (!DateTime.TryParseExact(ReadLine(), "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out start));

            DateTime end;

            do
            {
                Write("End date (dd/mm/yyyy):");
            } while (!DateTime.TryParseExact(ReadLine(), "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out end));

            Write("Room number:");
            var roomN = int.Parse(ReadLine());

            using (var context = new CegidDbContext())
            {
                var room = await context.Rooms.FirstOrDefaultAsync(r => r.Number == roomN);

                var reservation = new Reservation
                {
                    CustomerId = customerId,
                    Start      = start,
                    End        = end,
                    RoomId     = room.Id
                };
                context.Reservations.Add(reservation);
                await context.SaveChangesAsync();
            }
        }