コード例 #1
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (Check.IsNull(id))
            {
                return(RedirectToAction("Index"));
            }
            TravelerProfile travelerProfile = await ProfileManager.LoadUserAndTravelerProfile(User);

            using (var db = new ApplicationDbContext())
            {
                Models.RoomRequest.RoomRequest roomRequest = db.RoomRequests.Find(id);
                roomRequest.RoomRequestResponse = db.RoomRequestResponse.Find(roomRequest.RoomRequestResponse_ID);
                if (Check.IsNull(roomRequest, "RoomRequest Delete"))
                {
                    return(RedirectToAction("Index"));
                }
                if (roomRequest.ApplyingTraveler_ID != travelerProfile.ID)
                {
                    NotificationManager.AddException(new Exception("AccessViolation Roomrq Delete"));
                    return(RedirectToAction("Index"));
                }
                Models.Request.Request rq = await db.Requests.FindAsync(roomRequest.Request_ID);

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

                Models.VM.ProfilePreviewVM host = await ProfilesController.ProfilePreviewVM(rq.RequestOwner_ID);

                Models.RoomRequest.RoomRequestVMUser roomRequestVM = new Models.RoomRequest.RoomRequestVMUser(roomRequest, rq, host);
                return(View(roomRequestVM));
            }
        }
コード例 #2
0
        public async Task <ActionResult> Edit(Models.Request.RequestVMOwner requestVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    using (var db = new ApplicationDbContext())
                    {
                        var trackedRequest = await db.Requests.FindAsync(requestVM.ID);

                        trackedRequest.Accommodation = await db.Accommodations.FindAsync(trackedRequest.Accommodation_ID);

                        trackedRequest.Accommodation.AccomProfile = await db.AccommProfile.FindAsync(trackedRequest.Accommodation.AccomProfileID);

                        Models.Request.Request update = trackedRequest;
                        update.SetValues(requestVM);

                        db.Entry(trackedRequest).CurrentValues.SetValues(update);
                        await db.SaveChangesAsync();

                        NotificationManager.AddNotification(NotificationType.Success, "Your request has been updated succesfully");
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                    return(View(requestVM));
                }
            }
            return(View(requestVM));
        }
コード例 #3
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());
            }
        }
コード例 #4
0
        // GET: Requests/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (Check.IsNull(id))
            {
                NotificationManager.AddException(new Exception("Request Delete, ID was null"));
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                return(View());
            }
            TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

            using (var db = new ApplicationDbContext())
            {
                Models.Request.Request request = await db.Requests.FindAsync(id);

                if (Check.IsNull(request, "DeleteRequest"))
                {
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                    return(View());
                }
                if (request.RequestOwner_ID != tp.ID)
                {
                    NotificationManager.AddException(new Exception("Access Violation, Requesteditor is not requestowner"));
                }
                request.Accommodation = await AccommodationsController.LoadAccommodation(request.Accommodation_ID);

                Models.Request.RequestVMOwner rqVM = new Models.Request.RequestVMOwner(request);
                return(View(rqVM));
            }
        }
コード例 #5
0
        public static async Task <string> RoomRequestStats(Models.Request.Request request)
        {
            using (var db = new ApplicationDbContext())
            {
                IQueryable <Models.RoomRequest.RoomRequest> rReqs     = db.RoomRequests.Where(p => p.Request_ID == request.ID).Include(p => p.RoomRequestResponse);
                List <Models.RoomRequest.RoomRequest>       rReqsPend = await rReqs.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Pending).ToListAsync();

                int numrReqsPend = rReqsPend.Count;
                List <Models.RoomRequest.RoomRequest> rReqsDecl = await rReqs.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Declined).ToListAsync();

                int numrReqsDecl = rReqsDecl.Count;
                List <Models.RoomRequest.RoomRequest> rReqsApprov = await rReqs.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Approved).ToListAsync();

                int numrReqsApprov = rReqsApprov.Count;
                List <Models.RoomRequest.RoomRequest> rReqsPropos = await rReqs.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Proposed).ToListAsync();

                int numrReqsProp = rReqsPropos.Count;
                List <Models.RoomRequest.RoomRequest> rReqsReserv = await rReqs.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Reserved).ToListAsync();

                int numrReqsRes = rReqsReserv.Count;

                int numrReqs = numrReqsApprov + numrReqsPend + numrReqsProp + numrReqsRes + numrReqsDecl;
                return(numrReqs + " / " + numrReqsPend + " / " + numrReqsDecl + " / " + numrReqsApprov + " / " + numrReqsProp + " / " + numrReqsRes);
            }
        }
コード例 #6
0
        //GET: RoomRequests/Details/5
        public async Task <ActionResult> Details(int id)
        {
            try
            {
                using (var db = new ApplicationDbContext())
                {
                    Models.RoomRequest.RoomRequest roomRequest = await db.RoomRequests.FindAsync(id);

                    roomRequest.RoomRequestResponse = await db.RoomRequestResponse.FindAsync(roomRequest.RoomRequestResponse_ID);

                    if (Check.IsNull(roomRequest, "DetailsRoomRq"))
                    {
                        NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                        return(View());
                    }
                    Models.Request.Request rq = await db.Requests.FindAsync(roomRequest.Request_ID);

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

                    Models.VM.ProfilePreviewVM host = await ProfilesController.ProfilePreviewVM(rq.RequestOwner_ID);

                    Models.RoomRequest.RoomRequestVMUser roomRequestVM = new Models.RoomRequest.RoomRequestVMUser(roomRequest, rq, host);
                    return(View(roomRequestVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #7
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

            using (var db = new ApplicationDbContext())
            {
                Models.Request.Request requestDB = await db.Requests.FindAsync(id);

                if (requestDB.RequestOwner_ID != tp.ID)
                {
                    NotificationManager.AddException(new Exception("Access Violation, Requesteditor is not requestowner"));
                }
                IQueryable <Models.RoomRequest.RoomRequest> RoomRequestsToBeCanceled = db.RoomRequests.Where(p => p.Request_ID == id);
                List <Models.RoomRequest.RoomRequest>       rRqL = await RoomRequestsToBeCanceled.ToListAsync();

                foreach (var rRq in rRqL)
                {
                    rRq.Invalid();          //Set RoomRq toinvalid, user will see request was Deleted
                    db.Entry(rRq).State = EntityState.Modified;
                }


                requestDB.Delete();
                db.Entry(requestDB).State = EntityState.Modified;
                await db.SaveChangesAsync();

                NotificationManager.AddNotification(NotificationType.Success, "Your request has been deleted");
            }

            return(RedirectToAction("Index"));
        }
コード例 #8
0
        /// <summary>
        /// Finds rooms appropriate for roomrequest
        /// </summary>
        /// <param name="roomRequest"></param>
        /// <returns></returns>
        //public static async Task<List<Models.Accommodation.BedRoom>> GetSuitingRooms4RoomRequest(Models.RoomRequest.RoomRequest roomRequest)
        //{
        //    List<Models.Accommodation.BedRoom> roomsWCapacity = await GetFreeRooms(roomRequest.CheckInUser, roomRequest.CheckOutUser, roomRequest.Request_ID);
        //    List<Models.Accommodation.BedRoom> Rooms = new List<Models.Accommodation.BedRoom>();
        //    foreach (var room in roomsWCapacity)
        //    {
        //        if (!roomRequest.ShareRoom)
        //        {
        //            if (room.Vacant)
        //            {
        //                if (room.SingleBeds >= roomRequest.SingleBed && room.DoubleBeds >= roomRequest.DoubleBed)
        //                {
        //                    Rooms.Add(room);
        //                }
        //            }

        //        }
        //        else
        //        {
        //            if (room.SingleBeds >= roomRequest.SingleBed && room.DoubleBeds >= roomRequest.DoubleBed)
        //            {
        //                Rooms.Add(room);
        //            }
        //        }



        //    }

        //    return null;


        //}


        //public static async Task<List<Models.Accommodation.BedRoom>> GetFreeRooms(DateTime CheckIn, DateTime CheckOut, int rqID)
        //{
        //using (var db = new ApplicationDbContext())
        //{
        //    Models.Request.Request request = db.Requests.Find(rqID);
        //   // Models.Accommodation.Accommodation accom = db.Accommodations.Where(p => p.ID == request.Accommodation_ID).Include(p => p.BedRooms).Include(p => p.Capacity).FirstOrDefault();
        //   // int numbedRooms = accom.BedRooms.Count;
        //    IQueryable<Models.RoomRequest.RoomRequest> RoomRequests = db.RoomRequests.Where(p => p.Request_ID == rqID).Include(p => p.RoomRequestResponse); //Find all roomRequests and its response
        //    RoomRequests = RoomRequests.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Reserved); //Filter reserved RoomRequests
        //    if (RoomRequests == null || RoomRequests.ToList().Count == 0) //no reservation was made, all Bedrooms are vacant
        //    {
        //     //   return accom.BedRooms;
        //    }
        //    IQueryable<Models.RoomRequest.RoomRequest> RoomRequestsOutSmaller = RoomRequests.Where(p => p.CheckInUser < CheckIn && p.CheckOutUser < CheckOut); //exclude outlayers before
        //    IQueryable<Models.RoomRequest.RoomRequest> RoomRequestsOutBigger = RoomRequests.Where(p => p.CheckInUser > CheckIn && p.CheckOutUser > CheckOut); //exclude outlayer after
        //    RoomRequests = RoomRequests.Except(RoomRequestsOutSmaller); //Except outlayers
        //    RoomRequests = RoomRequests.Except(RoomRequestsOutBigger);
        //    //List<Models.RoomRequest.RoomRequest> filteredRoomRequestsReserved = await RoomRequests.Where(p => p.RoomRequestResponse.IsReserved()).ToListAsync();

        //    List<Models.RoomRequest.RoomRequest> filteredRoomRequestsReserved = await RoomRequests.Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Reserved).ToListAsync(); //catch empty List

        //    if (filteredRoomRequestsReserved == null || filteredRoomRequestsReserved.Count == 0) //no reservation was made, all Bedrooms are vacant
        //    {
        //       // return accom.BedRooms;
        //    }
        //    List<Models.Accommodation.BedRoom>[] BookedBedrooms = new List<Models.Accommodation.BedRoom>[numbedRooms];
        //    foreach (var rRq in filteredRoomRequestsReserved) //FindBedrooms and its occupation for the given time interval
        //    {
        //        var room = db.BedRooms.Find(rRq.Room_ID);

        //        BookedBedrooms[room.RoomNumber - 1].Add(room);
        //    }

        //    List<Models.Accommodation.BedRoom> FreeBedRooms = new List<Models.Accommodation.BedRoom>();
        //    for (int i = 0; i < numbedRooms; i++) //check if rooms are fully loaded
        //    {
        //        if (BookedBedrooms[i].Count == 0)
        //        {
        //            Models.Accommodation.BedRoom freeBedRoom = accom.BedRooms.Where(p => p.RoomNumber == i).FirstOrDefault(); //just add the roomspecification
        //            freeBedRoom.Vacant = true;
        //            FreeBedRooms.Add(freeBedRoom);
        //        }
        //        else //get detailed Booking status ->check the roomrequests for each room in that time //
        //        {
        //            List<Models.RoomRequest.RoomRequest> rRqRoom = filteredRoomRequestsReserved.Where(p => p.Room_ID == BookedBedrooms[i].FirstOrDefault().ID).ToList();
        //            int doublebedsOccupied = 0;
        //            int singlebedsOccupied = 0;
        //            bool shared = true;
        //            foreach (var rRq in rRqRoom)
        //            {
        //                doublebedsOccupied += rRq.DoubleBed;
        //                singlebedsOccupied += rRq.SingleBed;
        //                if (rRq.ShareRoom != shared) { shared = false; }
        //            }

        //            if (shared && doublebedsOccupied + singlebedsOccupied < BookedBedrooms[i].FirstOrDefault().MaxGuests)
        //            {
        //                Models.Accommodation.BedRoom SharedBedRoom = BookedBedrooms[i].FirstOrDefault();
        //                SharedBedRoom.DoubleBeds -= doublebedsOccupied;
        //                SharedBedRoom.SingleBeds -= singlebedsOccupied;
        //                SharedBedRoom.SharePossible = true;     //these rooms are shared in this moment
        //                FreeBedRooms.Add(SharedBedRoom);
        //            }

        //        }

        //    }

        //    return FreeBedRooms;
        //}
        // }

        //GET: Requests/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            using (var db = new ApplicationDbContext())
            {
                Models.Request.Request request = await db.Requests.FindAsync(id);

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

                if (Check.IsNull(request, "Edit Request"))
                {
                    NotificationManager.AddNotification(NotificationType.Warning, "Request does not exist!");
                    return(RedirectToAction("Index", "Home"));
                }
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (request.RequestOwner_ID != tp.ID)
                {
                    NotificationManager.AddException(new Exception("User is not the Requestowner, Access Violation"));
                    NotificationManager.AddNotification(NotificationType.Warning, "Access Violation");
                    return(RedirectToAction("Index", "Home"));
                }



                Models.Request.RequestVMOwner rqVM = new Models.Request.RequestVMOwner(request);

                return(View(rqVM));
            }
        }
コード例 #9
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());
            }
        }
コード例 #10
0
        public async Task <ActionResult> Edit(int?id) //id roomRq
        {
            try
            {
                if (!id.HasValue)
                {
                    return(RedirectToAction("Search", "Searches"));
                }
                TravelerProfile travelerProfile = await ProfileManager.LoadUserAndTravelerProfile(User);

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

                    if (Check.IsNull(roomRequest, "Edit roomRequest"))
                    {
                        return(RedirectToAction("Index"));
                    }
                    Models.Request.Request request = await db.Requests.FindAsync(roomRequest.Request_ID);

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

                    if (!request.IsValid())
                    {
                        NotificationManager.AddNotification(NotificationType.Info, "The request is invalid, you can't edit your roomrequest anymore");
                        return(RedirectToAction("Index"));
                    }
                    if (roomRequest.ApplyingTraveler_ID != travelerProfile.ID)
                    {
                        NotificationManager.AddException(new Exception("Access violation, this is not your Roomrequest! Edit RoomRequest", new AccessViolationException()));

                        return(RedirectToAction("Index"));
                    }
                    roomRequest.RoomRequestResponse = db.RoomRequestResponse.Find(roomRequest.RoomRequestResponse_ID);

                    if (roomRequest.RoomRequestResponse.IsApproved())
                    {
                        NotificationManager.AddNotification(NotificationType.Info, "You cannot edit an approved roomrequest!");
                        return(RedirectToAction("Index"));
                    }
                    if (roomRequest.RoomRequestResponse.IsReserved())
                    {
                        NotificationManager.AddNotification(NotificationType.Info, "You cannot edit a reserved roomrequest!");
                        return(RedirectToAction("Index"));
                    }
                    Models.VM.ProfilePreviewVM host = await ProfilesController.ProfilePreviewVM(request.RequestOwner_ID);

                    Models.RoomRequest.RoomRequestVMUser roomRequestEditVM = new Models.RoomRequest.RoomRequestVMUser(roomRequest, request, null);

                    return(View(roomRequestEditVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(RedirectToAction("Index"));
            }
        }
コード例 #11
0
        public async Task <ActionResult> Create([Bind(Exclude = "ID")] Models.Request.RequestVMOwner requestVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    Models.Accommodation.Likibu.AccomodationDetailsParam para    = new Models.Accommodation.Likibu.AccomodationDetailsParam(tp.Attributes.Language, tp.Attributes.Currency, requestVM.CheckIn.ToString(), requestVM.CheckOut.ToString());
                    Models.Accommodation.Likibu.AccomodationDetails      details = await Likibu.LikibuAccess.RequestAccomodationDetails(para, requestVM.AccomID);

                    ///
                    using (var db = new ApplicationDbContext())
                    {
                        requestVM.BedRooms    = details.offer.BedRooms;
                        requestVM.Lat         = details.offer.Lat;
                        requestVM.Lng         = details.offer.Lng;
                        requestVM.PricePNight = details.offer.PriceNight.ToString();
                        requestVM.PricePWeek  = details.offer.PriceWeek.ToString();
                        requestVM.PricepMonth = details.offer.PriceMonth.ToString();

                        details.offer.Destination = requestVM.Location;
                        details.offer.Thumbnails  = Models.Accommodation.Likibu.Offer.StringToArray(requestVM.ThumbsTemp).ToList();



                        Models.Request.Request rq = new Models.Request.Request(tp.ID, requestVM);

                        rq.Accommodation = new Models.Accommodation.Accommodation(details.offer.MaxGuests, details.offer.BedRooms); //AccommodationModel is generated here
                        if (!rq.Accommodation.Verified)
                        {
                            throw new Exception("Accommodation abstraction failed");
                        }
                        string currency = ProfilesController.Currency(tp.Attributes.Currency);
                        rq.Accommodation.AccomProfile = new Models.Accommodation.AccommodationProfile(details.offer, currency);

                        db.Requests.Add(rq);
                        await db.SaveChangesAsync();

                        NotificationManager.AddNotification(NotificationType.Success, "Your Request has been saved!");

                        return(RedirectToAction("Create", "RoomRequests", new { id = rq.ID }));
                    }
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                    return(RedirectToAction("Search", "Searches"));
                }
            }
            return(View(requestVM));
        }
コード例 #12
0
        public async Task <ActionResult> CreateFree(Models.Request.RequestVMFree requestVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    tp = await ProfilesController.LoadProfile(tp.ID);

                    Models.Request.Request rq = new Models.Request.Request(tp.ID, requestVM); //AccommodationModel is generated here

                    rq.Accommodation = new Models.Accommodation.Accommodation(0, requestVM.BedRooms);
                    if (!rq.Accommodation.Verified)
                    {
                        throw new Exception("Accommodation abstraction failed");
                    }
                    // get locationIDs
                    List <Models.Accommodation.Likibu.Destination> dest = await Likibu.LikibuAccess.DestinationRequest(requestVM.Location, tp.Attributes.Language, 1.ToString());

                    //Models.Accommodation.Likibu.DestinationDetail destDetail = await Likibu.LikibuAccess.DestinationDetailRequest();// Todo add LatLng


                    rq.Accommodation.AccomProfile = new Models.Accommodation.AccommodationProfile(dest.FirstOrDefault(), requestVM.BedRooms, requestVM.Link);
                    if (!requestVM.Lat.HasValue || !requestVM.Lng.HasValue)
                    {
                        float[] lnglat = new float[2];
                        lnglat = GoogleWrapper.LongLat2DoubleAr(await GoogleWrapper.GetGeolocation(requestVM.Location));

                        rq.Accommodation.AccomProfile.Lng = lnglat[0];
                        rq.Accommodation.AccomProfile.Lat = lnglat[1];
                    }
                    else
                    {
                        rq.Accommodation.AccomProfile.Lng = requestVM.Lng.Value;
                        rq.Accommodation.AccomProfile.Lat = requestVM.Lat.Value;
                    }
                    using (var db = new ApplicationDbContext())
                    {
                        db.Requests.Add(rq);
                        await db.SaveChangesAsync();
                    }
                    NotificationManager.AddNotification(NotificationType.Success, "Your request has been saved!");
                    return(RedirectToAction("Index", "Home"));
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                }
            }
            return(View(requestVM));
        }
コード例 #13
0
        public async Task <ActionResult> DetailsHost(int?id) //RequestID
        {
            try
            {
                if (!id.HasValue)
                {
                    return(RedirectToAction("Index", "Requests"));
                }
                id = id.Value;
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (Check.IsNull(tp, "DetailsOwner"))
                {
                    return(RedirectToAction("Create", "Profiles"));
                }
                using (var db = new ApplicationDbContext())
                {
                    Models.Request.Request request = await db.Requests.FindAsync(id);

                    if (Check.IsNull(request, "DetailsOwner"))
                    {
                        return(RedirectToAction("Index", "Requests"));
                    }
                    if (request.IsDeleted("DetailsOwner"))
                    {
                        return(RedirectToAction("Index", "Requests"));
                    }

                    if (request.RequestOwner_ID != tp.ID)
                    {
                        NotificationManager.AddException(new Exception("Access violation, DetailsOwner, RqCtrl"));
                        return(RedirectToAction("Index", "Requests"));
                    }

                    string rrqstats = await RoomRequest.RoomRequestsController.RoomRequestStats(request);

                    request.Accommodation = await db.Accommodations.FindAsync(request.Accommodation_ID);

                    request.Accommodation.AccomProfile = await db.AccommProfile.FindAsync(request.Accommodation.AccomProfileID);

                    Models.Request.RequestVMOwner requestVM = new Models.Request.RequestVMOwner(request, rrqstats);
                    return(View(requestVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                return(RedirectToAction("Index", "Requests"));
            }
        }
コード例 #14
0
        public IActionResult Post([FromBody] Models.Request.Request request)
        {
            // Begin building Response
            var response = new Models.Response.Response {
                RequestId = request.RequestId
            };

            // Smart Home Intents use a single object in inputs, containing the intent value, and a payload object with automation-specific objects.
            if (request.Inputs == null || request.Inputs.Count != 1)
            {
                response.Payload = new Models.Response.ErrorResponsePayload {
                    ErrorCode = "protocolError"
                };
                return(BadRequest(response));
            }

            var input = request.Inputs[0];

            switch (input)
            {
            case Models.Request.SyncIntent syncIntent:
                response.Payload = _syncIntentHandler.Handle(syncIntent);
                return(Ok(response));

            case Models.Request.QueryIntent queryIntent:
                response.Payload = _queryIntentHandler.Handle(queryIntent);
                return(Ok(response));

            case Models.Request.ExecuteIntent executeIntent:
                response.Payload = _executeIntentHandler.Handle(executeIntent);
                return(Ok(response));

            case Models.Request.DisconnectIntent disconnectIntent:
                _disconnectIntentHandler.Handle(disconnectIntent);
                return(Ok());
            }

            // No valid intents found, return error
            response.Payload = new Models.Response.ErrorResponsePayload {
                ErrorCode = "protocolError"
            };
            return(BadRequest(response));
        }
コード例 #15
0
        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 }));
            }
        }
コード例 #16
0
        /// <summary>
        /// Display Details of a certain Request to User
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // GET: Requests/Details/5

        public async Task <ActionResult> Details(int?id)
        {
            try
            {
                if (id.HasValue)
                {
                    id = id.Value;
                }
                else
                {
                    return(View());
                }

                using (var db = new ApplicationDbContext())
                {
                    Models.Request.Request request = await db.Requests.FindAsync(id);

                    if (Check.IsNull(request, "RequestDetails"))
                    {
                        return(RedirectToAction("Search", "Searches"));
                    }
                    if (request.IsDeleted("RequestDetails"))
                    {
                        return(RedirectToAction("Search", "Searches"));
                    }
                    ///Loads Accommodation with Profile

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

                    Models.VM.ProfilePreviewVM rqOwnerVM = await ProfilesController.ProfilePreviewVM(request.RequestOwner_ID);

                    Models.Request.RequestVMUser requestVM = new Models.Request.RequestVMUser(request, rqOwnerVM);
                    return(View(requestVM));
                }
            }
            catch (Exception e) {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                return(View());
            }
        }
コード例 #17
0
        public async Task <ActionResult> Index()
        {
            try
            {
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                if (Check.IsNull(tp, "Index RoomRequests"))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                using (var db = new ApplicationDbContext())
                {
                    IQueryable <Models.RoomRequest.RoomRequest>  IQuery     = db.RoomRequests.Where(p => p.ApplyingTraveler_ID == tp.ID).Include(p => p.RoomRequestResponse);
                    IEnumerable <Models.RoomRequest.RoomRequest> roomRqList = await IQuery.ToListAsync();

                    List <Models.RoomRequest.RoomRequestListUser> resultList = new List <Models.RoomRequest.RoomRequestListUser>();

                    foreach (var rRq in roomRqList)
                    {
                        Models.Request.Request rq = await db.Requests.FindAsync(rRq.Request_ID);

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

                        Models.VM.ProfilePreviewVM OwnerPrev = await ProfilesController.ProfilePreviewVM(rq.RequestOwner_ID);

                        Models.RoomRequest.RoomRequestListUser rqVM = new Models.RoomRequest.RoomRequestListUser(rRq, rq, OwnerPrev);
                        resultList.Add(rqVM);
                    }
                    return(View(resultList));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
コード例 #18
0
        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 }));
            }
        }
コード例 #19
0
        public async Task <ActionResult> Create(int?id) //Request id
        {
            try
            {
                if (!id.HasValue)
                {
                    return(RedirectToAction("Search", "Searches"));
                }
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                using (var db = new ApplicationDbContext())
                {
                    TravelerProfileSearchSession searchSession = await db.LikibuSearchSession.FindAsync(tp.TravelerSearchID); //to fill checkDates, Location

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

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

                    if (Check.IsNull(request, "Create RoomRequest"))
                    {
                        NotificationManager.AddNotification(NotificationType.Warning, "Request is not valid");
                        return(RedirectToAction("Search", "Searches"));
                    }
                    if (request.IsDeleted("CreateRoomRequest, rq deleted"))
                    {
                        NotificationManager.AddNotification(NotificationType.Warning, "Request is not valid");
                        return(RedirectToAction("Search", "Searches"));
                    }
                    if (request.IsClosed()) //dann keine RoomRequests mehr
                    {
                        NotificationManager.AddNotification(NotificationType.Info, "You can't apply for closed requests");
                        return(RedirectToAction("Search", "Searches"));
                    }
                    //calc Valid Time here
                    DateTime CheckIn     = request.CheckIn;
                    DateTime CheckOut    = request.CheckOut;
                    DateTime chckinUser  = DateTime.Parse(searchSession.CheckIn);
                    DateTime chckoutUser = DateTime.Parse(searchSession.CheckOut);
                    if (chckinUser < CheckIn)
                    {
                        CheckIn = chckinUser;
                    }

                    if (chckoutUser > CheckOut)
                    {
                        CheckOut = chckoutUser;
                    }


                    Models.RoomRequest.RoomRequestVMUser roomRequestVM = new Models.RoomRequest.RoomRequestVMUser(CheckIn, CheckOut, request);
                    if (tp.ID == request.RequestOwner_ID)
                    {
                        roomRequestVM.RequestOwner = true;
                    }
                    return(View(roomRequestVM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
コード例 #20
0
        public async Task <ActionResult> SelectFlatmates(int id, int update, int rrqid)  //id RequestID
        {
            try
            {
                TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);


                using (var db = new ApplicationDbContext())
                {
                    Models.Request.Request request = await db.Requests.FindAsync(id);

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

                    if (Check.IsNull(request, "UpdateSelectFlatmates"))
                    {
                        return(RedirectToAction("Index", "Requests"));
                    }
                    if (request.RequestOwner_ID != tp.ID)
                    {
                        NotificationManager.AddException(new Exception("User is not RequestOwner, Access Violation, AcceptTraveler", new AccessViolationException()));
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (update != 0 && rrqid != 0)
                    {
                        Models.RoomRequest.RoomRequest roomRequest = await db.RoomRequests.FindAsync(rrqid);

                        if (Check.IsNull(roomRequest, "UpdateSelectFlatmates"))
                        {
                            return(RedirectToAction("Index", "Requests"));
                        }
                        roomRequest.RoomRequestResponse = await db.RoomRequestResponse.FindAsync(roomRequest.RoomRequestResponse_ID);

                        if (roomRequest.IsDeleted("RoomRequest") || request.IsDeleted("RoomRequest"))
                        {
                            NotificationManager.AddNotification(NotificationType.Warning, "RoomRequest is not valid, Request might has been been deleted");
                            return(RedirectToAction("Index", "Home"));
                        }

                        var trackedRoomRq      = roomRequest;
                        var trackedRRqResponse = roomRequest.RoomRequestResponse;

                        if (update > 0)
                        {
                            roomRequest.RoomRequestResponse.Approve();
                            NotificationManager.AddNotification(NotificationType.Success, "Flatmate approved!");
                        }
                        if (update < 0)
                        {
                            roomRequest.RoomRequestResponse.Decline();
                            NotificationManager.AddNotification(NotificationType.Success, "Flatmate declined!");
                        }

                        db.Entry(trackedRoomRq).CurrentValues.SetValues(roomRequest);
                        db.Entry(trackedRRqResponse).CurrentValues.SetValues(trackedRRqResponse);
                        await db.SaveChangesAsync();
                    }

                    IQueryable <Models.RoomRequest.RoomRequest> roomRequestQuery = db.RoomRequests.Where(p => p.Request_ID == id).Include(p => p.RoomRequestResponse).Where(p => p.RoomRequestResponse.responseStatus == Models.RoomRequest.RoomRequestResponseStatus.Pending);
                    List <Models.RoomRequest.RoomRequest>       roomRequestList  = await roomRequestQuery.ToListAsync();

                    List <Models.RoomRequest.RReqVMListItemRqOwn> roomRequestVMList = new List <Models.RoomRequest.RReqVMListItemRqOwn>();
                    foreach (var roomRq in roomRequestList)
                    {
                        if (roomRq.IsValid())
                        {
                            Models.VM.ProfilePreviewVM applicantVMPrev = await ProfilesController.ProfilePreviewVM(roomRq.ApplyingTraveler_ID);

                            roomRequestVMList.Add(new Models.RoomRequest.RReqVMListItemRqOwn(roomRq, request, applicantVMPrev));
                        }
                    }
                    string rrqstats = await RoomRequestStats(request);

                    Models.RoomRequest.RReqVMListRqOwn SelectFM = new Models.RoomRequest.RReqVMListRqOwn(request.ID, roomRequestVMList, rrqstats);

                    return(View(SelectFM));
                }
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong");
                return(RedirectToAction("Index", "Requests"));
            }
        }