public IActionResult MakeReservation(Customer customerValues)
        {
            fullReservation = FullReservationFactory.Instance.CreateSingle(GetReservations());
            if (fullReservation.RoomsToBook == null)
            {
                throw new ArgumentNullException();
            }
            fullReservation.Customer = customerValues;
            if (!((CustomerAccess)customerAccess).FindCustomer(fullReservation.Customer.PhoneNumber))
            {
                ((CustomerAccess)customerAccess).CreateCustomer(fullReservation.Customer);
            }
            try
            {
                ((ReservationAccess)reservationAccess).CreateReservation(fullReservation);
            }
            catch (Exception e)
            {
                throw e;
            }
            try
            {
                SendConfirmationEmail(customerValues.Email);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(RedirectToAction("Index", "Rooms"));
        }
 public IActionResult Index()
 {
     try
     {
         //Make in factory
         fullReservation = FullReservationFactory.Instance.CreateSingle(GetReservations());
         return(View(fullReservation));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#3
0
        public void CreateReservation(FullReservationModel reservationModel)
        {
            try
            {
                SqlConnection conn;
                using (conn = GetSqlConnection())
                {
                    conn.ConnectionString = Connectionstring;
                    SqlCommand command = GetSqlCommand();
                    command.Connection  = conn;
                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "MakeReservation";

                    foreach (BookingModel booking in reservationModel.RoomsToBook)
                    {
                        command.Parameters.AddWithValue("@RoomNumber", booking.Room.RoomNumber);
                        command.Parameters.AddWithValue("@customerPhone", reservationModel.Customer.PhoneNumber);
                        command.Parameters.AddWithValue("@StartDate", booking.StartDate);
                        command.Parameters.AddWithValue("@EndDate", booking.EndDate);


                        try
                        {
                            conn.Open();
                            command.ExecuteNonQuery();

                            command.Parameters.Clear();
                        }
                        catch (SqlException ex)
                        {
                            throw ex;
                            //Log exception
                            //throw;
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }