public static void AddNote(BookingLog note, int roomId, int guestId, int hotelId)
        {
            using (var connection = new SqlConnection(_connectionString))
                using (var command = connection.CreateCommand())
                {
                    try
                    {
                        connection.Open();
                        command.CommandText = $"INSERT into BookingLog values ('{roomId}','{guestId}'," +
                                              $"'{hotelId}','{note.ArrivalDate}','{note.DepartureDate}','{note.Payment}')";

                        var affectedRows = command.ExecuteNonQuery(); //число строк которые подвергнуты каким либо изменениям

                        if (affectedRows < 1)
                        {
                            throw new Exception("Вставка не была произведена");
                        }
                    }
                    catch (SqlException exception)
                    {
                        //TODO обработка ошибки
                        Console.WriteLine(exception.Message);
                        //throw;
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                        //TODO обработка ошибки
                        //throw;
                    }
                }
        }
Пример #2
0
        public static void BookingNumber(BookingLog note, Room room, User user, Hotel hotel)
        {
            //note.RoomNumber = room.Number;
            //note.GuestName = user.Login;
            //note.HotelName = hotel.Name;
            user.Id = AccountsTableDataService.GetAccountId(user.Login);

            Console.Write("Please ender data:\n" +
                          "ArrivalDate (dd.mm.yyyy): ");
            note.ArrivalDate = DateTime.Parse(Console.ReadLine());

            Console.Write("DepartureDate (dd.mm.yyyy): ");
            note.DepartureDate = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("\n1) To book \n2) To Pay");
            int choice = int.Parse(Console.ReadLine());

            if (choice == 1)
            {
                note.Payment = 0;
            }
            else if (choice == 2)
            {
                note.Payment = (note.DepartureDate - note.ArrivalDate).TotalDays * RoomsTableDataService.GetRoomPrice(room.Id);
            }

            BookingLogTableDataService.AddNote(note, room.Id, user.Id, hotel.Id);
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("BookingLogId,CreatedBy,CreatedDate,LastModifiedDate,LastModifiedBy,StaffId,CustomerId,ActivityTypeId")] BookingLog bookingLog)
        {
            if (id != bookingLog.BookingLogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    dataContext.Update(bookingLog);
                    await dataContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookingLogExists(bookingLog.BookingLogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActivityTypeId"] = new SelectList(dataContext.ActivityType, "ActivityTypeId", "Title,Price,StartDate,EndDate,Vehicle", bookingLog.ActivityTypeId);
            ViewData["CustomerId"]     = new SelectList(dataContext.Customer, "CustomerId", "FirstName", bookingLog.CustomerId);
            ViewData["StaffId"]        = new SelectList(dataContext.Staff, "StaffId", "FirstName", bookingLog.StaffId);
            return(View(bookingLog));
        }
Пример #4
0
        static void Main(string[] args)
        {
            User user        = new User();
            var  dataService = new AccountsTableDataService();

            while (true)
            {
                System.Console.Clear();
                System.Console.Write("1) Registration \n" +
                                     "2) Authorization \n" +
                                     "3) Exit \n" +
                                     "Choice: ");
                int choice = int.Parse(System.Console.ReadLine());

                if (choice == 1)
                {
                    Registration.SignUp(user, dataService);
                }
                else if (choice == 2)
                {
                    Authorization.SignIn(user);

                    List <Hotel> hotels = HotelsTableDataService.GetAllHotels();
                    for (int i = 0; i < hotels.Count; i++)
                    {
                        System.Console.WriteLine($"{i+1}) {hotels[i].Name}");
                    }
                    System.Console.Write("Choice: ");
                    int hotelPosition = int.Parse(System.Console.ReadLine());

                    List <Room> rooms = RoomsTableDataService.GetAvailableRooms(hotels[hotelPosition - 1].Id);
                    System.Console.WriteLine("{0,7} | {1,15} | {2,10}", "№", "Category", "Price");

                    for (int i = 0; i < rooms.Count; i++)
                    {
                        System.Console.Write($"{i+1}) ");
                        rooms[i].Show(i + 1);
                    }
                    System.Console.Write("Please, make your choice: ");
                    int roomPosition = int.Parse(System.Console.ReadLine());

                    BookingLog note = new BookingLog();

                    Reservation.BookingNumber(note, rooms[roomPosition - 1], user, hotels[hotelPosition - 1]);
                    System.Console.ReadLine();
                }
                else
                {
                    System.Environment.Exit(0);
                }
            }
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("BookingLogId,CreatedBy,CreatedDate,LastModifiedDate,LastModifiedBy,StaffId,CustomerId,ActivityTypeId")] BookingLog bookingLog)
        {
            if (ModelState.IsValid)
            {
                dataContext.Add(bookingLog);
                await dataContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActivityTypeId"] = new SelectList(dataContext.ActivityType, "ActivityTypeId", "Title", bookingLog.ActivityTypeId);
            ViewData["CustomerId"]     = new SelectList(dataContext.Customer, "CustomerId", "FirstName", bookingLog.CustomerId);
            ViewData["StaffId"]        = new SelectList(dataContext.Staff, "StaffId", "FirstName", bookingLog.StaffId);
            return(View(bookingLog));
        }