Exemplo n.º 1
0
        public IActionResult UserHome()
        {
            var user = authProvider.GetCurrentUser();


            ReservationUserViewModel vm = new ReservationUserViewModel();

            vm.User     = userDAL.GetUser(user.Username);
            vm.Pets     = petDAO.GetAllPets(user.Id);
            vm.Accepted = reservationDAO.GetAllAcceptedReservations(user.Id);
            vm.Pending  = reservationDAO.GetAllPendingReservations(user.Id);
            vm.Declined = reservationDAO.GetAllDeclinedReservations(user.Id);

            return(View(vm));
        }
Exemplo n.º 2
0
        public IActionResult PendingReservation(int id)
        {
            ReservationUserViewModel vm = new ReservationUserViewModel();

            var user = authProvider.GetCurrentUser();

            vm.User = userDAL.GetUserById(user.Id);

            // got to figure out the reservationid to pass over

            vm.User        = userDAL.GetUser(user.Username);
            vm.Pets        = petDAO.GetAllPets(user.Id);
            vm.Reservation = reservationDAO.GetPendingReservation(user.Id, id);

            return(View(vm));
        }
Exemplo n.º 3
0
        public IActionResult Reservation()
        {
            if (!authProvider.IsLoggedIn)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var user = authProvider.GetCurrentUser();

            ReservationUserViewModel vm = new ReservationUserViewModel();

            vm.User         = userDAL.GetUser(user.Username);
            vm.Reservations = reservationDAO.GetAllReservationsForUser(user.Id);
            vm.Pets         = petDAO.GetAllPets(user.Id);

            return(View(vm));
        }
Exemplo n.º 4
0
        public IActionResult Reservation(ReservationUserViewModel vm)
        {
            if (vm.InvitedUser.Username == null)
            {
                return(RedirectToAction("Reservation", "Reservation"));
            }

            var user = authProvider.GetCurrentUser();

            vm.User        = userDAL.GetUserById(user.Id);
            vm.InvitedUser = userDAL.GetUser(vm.InvitedUser.Username);

            vm.Reservation.StartTime = vm.Reservation.StartTime.AddHours(vm.StartHour);
            vm.Reservation.StartTime = vm.Reservation.StartTime.AddMinutes(vm.StartMinute);
            vm.Reservation.EndTime   = vm.Reservation.EndTime.AddHours(vm.EndHour);
            vm.Reservation.EndTime   = vm.Reservation.EndTime.AddMinutes(vm.EndMinute);
            reservationDAO.AddReservation(vm);


            return(RedirectToAction("UserHome", "Account"));
        }
Exemplo n.º 5
0
        public int AddReservation(ReservationUserViewModel reservation)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    string sql = @"
                        begin tran;
                        Declare @resId int;
                        Insert Into Reservations Values (@address, @startTime, @endTime, @petName, @description); 
                        Select @resId = @@Identity;
                        Insert into users_reservations(userId, reservationId, status) values(@userId, @resId, 2);
                        Insert into users_reservations(userId, reservationId, status) values(@invitedUserId, @resId, 1);
                        commit tran;
                        Select @resId;
                        ";

                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@address", reservation.Reservation.Address);
                    cmd.Parameters.AddWithValue("@startTime", reservation.Reservation.StartTime);
                    cmd.Parameters.AddWithValue("@endTime", reservation.Reservation.EndTime);
                    cmd.Parameters.AddWithValue("@petName", reservation.Reservation.PetName);
                    cmd.Parameters.AddWithValue("@userId", reservation.User.Id);
                    cmd.Parameters.AddWithValue("@description", reservation.Reservation.Description);
                    cmd.Parameters.AddWithValue("@invitedUserId", reservation.InvitedUser.Id);

                    int Id = Convert.ToInt32(cmd.ExecuteScalar());


                    return(Id);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }