Exemplo n.º 1
0
        [HttpGet]                                           ///Todo implement Reservation Validation and Edit View appropriate    Preselection  of Profiles
        public async Task <ActionResult> SelectRoom(int id) // RoomRequest id
        {
            try
            {
                using (var db = new ApplicationDbContext())
                {
                    Models.RoomRequest.RoomRequest roomRequest = db.RoomRequests.Find(id);
                    roomRequest.RoomRequestResponse = await db.RoomRequestResponse.FindAsync(roomRequest.RoomRequestResponse_ID);

                    Models.VM.ProfilePreviewVM applicantPrevVM = await ProfilesController.ProfilePreviewVM(roomRequest.ApplyingTraveler_ID);

                    List <Models.RoomRequest.RoomRequest> reservations = await db.RoomRequests.Where(p => p.Request_ID == roomRequest.Request_ID).Include(p => p.RoomRequestResponse).Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Reserved).ToListAsync();

                    Models.Request.Request rq = db.Requests.Where(p => p.ID == roomRequest.Request_ID).Include(p => p.Accommodation).Include(p => p.Accommodation.BedRooms).FirstOrDefault();
                    Models.RoomRequest.RoomRequestVMOwner applicantVM = new Models.RoomRequest.RoomRequestVMOwner(roomRequest, applicantPrevVM);

                    Models.Request.SelectRoomVM sRVM = new Models.Request.SelectRoomVM(applicantVM, reservations, rq.Accommodation.BedRooms);
                    return(View(sRVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                return(View());
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Reservations(int?id) //RequestID
        {
            try
            {
                if (!id.HasValue)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                id = id.Value;
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (Check.IsNull(tp, "Index RoomRequests"))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                using (var db = new ApplicationDbContext())
                {
                    Models.Request.Request rq = await db.Requests.FindAsync(id);

                    rq.Accommodation = await AccommodationsController.LoadAccommodation(rq.Accommodation_ID);



                    IQueryable <Models.RoomRequest.RoomRequest> IQuery           = db.RoomRequests.Where(p => p.Request_ID == id).Include(p => p.RoomRequestResponse);
                    IQueryable <Models.RoomRequest.RoomRequest> Reservations     = IQuery.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Reserved);
                    IQueryable <Models.RoomRequest.RoomRequest> Approvals        = IQuery.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Approved);
                    List <Models.RoomRequest.RoomRequest>       ReservationsList = await Reservations.ToListAsync();

                    List <Models.RoomRequest.RoomRequestVMOwner> resListVM     = new List <Models.RoomRequest.RoomRequestVMOwner>();
                    List <Models.RoomRequest.RoomRequest>        ApprovalsList = await Approvals.ToListAsync();

                    List <Models.RoomRequest.RoomRequestVMOwner> apprListVM = new List <Models.RoomRequest.RoomRequestVMOwner>();
                    foreach (var res in ReservationsList)
                    {
                        Models.VM.ProfilePreviewVM tpVMPrev = await ProfilesController.ProfilePreviewVM(res.ApplyingTraveler_ID);

                        Models.RoomRequest.RoomRequestVMOwner rRqVM = new Models.RoomRequest.RoomRequestVMOwner(res, tpVMPrev);
                        resListVM.Add(rRqVM);
                    }
                    foreach (var appr in ApprovalsList)
                    {
                        Models.VM.ProfilePreviewVM tpVMPrev = await ProfilesController.ProfilePreviewVM(appr.ApplyingTraveler_ID);

                        Models.RoomRequest.RoomRequestVMOwner rRqVM = new Models.RoomRequest.RoomRequestVMOwner(appr, tpVMPrev);
                        apprListVM.Add(rRqVM);
                    }
                    Models.RoomRequest.ReservationsVM reservationsVM = new Models.RoomRequest.ReservationsVM(rq.Accommodation.BedRooms, resListVM, apprListVM, rq);


                    return(View(reservationsVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                return(View());
            }
        }
        public async Task <ActionResult> Propose(int id, int rqid) // id RoomRequestID
        {
            try
            {
                TravelerProfile travelerProfile = await ProfileManager.LoadUserAndTravelerProfile(User);

                using (var db = new ApplicationDbContext())
                {
                    Models.RoomRequest.RoomRequest roomRequest = await db.RoomRequests.FindAsync(id); //test with null!!!

                    if (Check.IsNull(roomRequest, "Propose"))
                    {
                        return(RedirectToAction("SelectFlatmates", new { id = rqid, update = 0, rrqid = 0 }));
                    }

                    Models.Request.Request request = await db.Requests.FindAsync(roomRequest.Request_ID);

                    if (Check.IsNull(request, "Propose"))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    if (roomRequest.IsDeleted("Propose") || request.IsDeleted("Propose")) //Todo delete RoomRequest if request is deleted
                    {
                        NotificationManager.AddNotification(NotificationType.Warning, "RoomRequest is not valid, Request might has been deleted");
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (request.RequestOwner_ID != travelerProfile.ID)
                    {
                        NotificationManager.AddException(new Exception("Access Violation @Propose, RoomRqCtrl", new AccessViolationException()));
                        return(RedirectToAction("Index", "Home"));
                    }
                    Models.RoomRequest.RoomRequestVMOwner roomRequestVM = new Models.RoomRequest.RoomRequestVMOwner(roomRequest);
                    return(View(roomRequestVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(RedirectToAction("SelectFlatmates", new { id = rqid, update = 0, rrqid = 0 }));
            }
        }
        // GET: RoomRequests/Details/5
        public async Task <ActionResult> DetailsHost(int?id)
        {
            if (Check.IsNull(id))
            {
                return(View());
            }
            using (var db = new ApplicationDbContext())
            {
                Models.RoomRequest.RoomRequest roomRequest = await db.RoomRequests.FindAsync(id);

                if (Check.IsNull(roomRequest, "DetailsRoomRqOwner"))
                {
                    return(View());
                }
                roomRequest.RoomRequestResponse = await db.RoomRequestResponse.FindAsync(roomRequest.RoomRequestResponse_ID);

                Models.VM.ProfilePreviewVM applPreVM = await ProfilesController.ProfilePreviewVM(roomRequest.ApplyingTraveler_ID);

                Models.RoomRequest.RoomRequestVMOwner roomRequestVM = new Models.RoomRequest.RoomRequestVMOwner(roomRequest, applPreVM);
                return(View(roomRequestVM));
            }
        }
        public async Task <ActionResult> Propose(Models.RoomRequest.RoomRequestVMOwner roomRqVM) // id RoomRequestID
        {
            try
            {
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                using (var db = new ApplicationDbContext())
                {
                    Models.RoomRequest.RoomRequest roomRequest = await db.RoomRequests.FindAsync(roomRqVM.ID);

                    Models.Request.Request request = await db.Requests.FindAsync(roomRequest.Request_ID);

                    if (request.RequestOwner_ID != tp.ID)
                    {
                        throw new Exception("Access Violation", new AccessViolationException());
                    }
                    roomRequest.RoomRequestResponse = await db.RoomRequestResponse.FindAsync(roomRequest.RoomRequestResponse_ID);

                    Models.RoomRequest.RoomRequest roomRequestUpdate = roomRequest;

                    roomRequestUpdate.SetValues(roomRqVM);
                    db.Entry(roomRequest).CurrentValues.SetValues(roomRequestUpdate);
                    db.Entry(roomRequest.RoomRequestResponse).CurrentValues.SetValues(roomRequestUpdate.RoomRequestResponse);
                    await db.SaveChangesAsync();

                    NotificationManager.AddNotification(NotificationType.Success, "Your proposal has been saved!");
                    return(RedirectToAction("SelectFlatmates", new { id = roomRqVM.Request_ID, update = 0, rrqid = 0 }));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                return(RedirectToAction("SelectFlatmates", new { id = roomRqVM.Request_ID, update = 0, rrqid = 0 }));
            }
        }