public IHttpActionResult PostAllBookingsView(AllBookingsView allBookingsView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AllBookingsViews.Add(allBookingsView);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AllBookingsViewExists(allBookingsView.Room_Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = allBookingsView.Room_Id }, allBookingsView));
        }
        public IHttpActionResult PutAllBookingsView(int id, AllBookingsView allBookingsView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != allBookingsView.Room_Id)
            {
                return(BadRequest());
            }

            db.Entry(allBookingsView).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AllBookingsViewExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetAllBookingsView(int id)
        {
            AllBookingsView allBookingsView = db.AllBookingsViews.Find(id);

            if (allBookingsView == null)
            {
                return(NotFound());
            }

            return(Ok(allBookingsView));
        }
        public IHttpActionResult DeleteAllBookingsView(int id)
        {
            AllBookingsView allBookingsView = db.AllBookingsViews.Find(id);

            if (allBookingsView == null)
            {
                return(NotFound());
            }

            db.AllBookingsViews.Remove(allBookingsView);
            db.SaveChanges();

            return(Ok(allBookingsView));
        }
Пример #5
0
        /// <summary>
        /// Method that posts the tavlebooking to the database, after it has checked if its possible in the chosen timespan.
        /// </summary>
        /// <param name="tavleEndTime">The total time for the selected tavlebooking (Comes from the Booktavle Method)</param>
        /// <param name="myTavleBooking">The chosen tavlebooking. This value comes from the SelectedDuration, and SelectedTavleStartTime properties</param>
        /// <returns></returns>
        public static async Task BookTavle(TimeSpan tavleEndTime, TavleBooking myNewTavleBooking)
        {
            AllBookingsView tempSelectedBooking = Reference.SelectedBooking;
            var             doesUserHaveAnyTavleBookingsForThisRoom = (from t in Reference.Tavlebookings
                                                                       select t).Where(x => x.Booking_Id == Reference.SelectedBooking.Booking_Id).ToList();

            if (doesUserHaveAnyTavleBookingsForThisRoom.Count > 0)
            {
                DialogHandler.Dialog("Det er ikke muligt at booke flere end 1 tavle\nSlet venligst eksisterende tavler og book derefter igen.", "For mange bookede tavler");
                return;
            }
            else
            {
                if (Reference.SelectedBooking.Type == "Klasselokale")
                {
                    var numberOfTavleBookingsForThisRoomOnThatDay = (from t in Reference.Tavlebookings
                                                                     join b in AllBookingsViewCatalogSingleton.Instance.AllBookings on t.Booking_Id equals b.Booking_Id
                                                                     select new
                    {
                        BookingId = t.Booking_Id,
                        UserId = b.User_Id,
                        RoomId = b.Room_Id,
                        BookingDate = b.Date,
                        BookingStart = b.BookingStart,
                        BookingEnd = b.BookingEnd,
                        TavleId = t.Tavle_Id,
                        TavleStart = t.Time_start,
                        TavleEnd = t.Time_end
                    }).Where(x => Reference.SelectedBooking.Room_Id == x.RoomId && Reference.SelectedBooking.Date == x.BookingDate).ToList();
                    if (numberOfTavleBookingsForThisRoomOnThatDay.Count > 0 && numberOfTavleBookingsForThisRoomOnThatDay.Count <= 2)
                    {
                        var checkTavleTime = (from t in numberOfTavleBookingsForThisRoomOnThatDay
                                              select t).Where(x => (Reference.SelectedTavleStartTime + TimeSpan.FromSeconds(1)) <= x.TavleEnd && (tavleEndTime - TimeSpan.FromSeconds(1)) >= x.TavleStart).ToList();
                        if (checkTavleTime.Count == 0)
                        {
                            // INSERT
                            if (await DialogHandler.GenericYesNoDialog("Er du sikker på du vil booke denne tavletid?\nKvittering på tavlen vil blive tilsendt via mail", "Book Book Tavle?", "Ja", "Fortryd"))
                            {
                                await PersistancyService.SaveInsertAsJsonAsync(myNewTavleBooking, "TavleBookings");

                                MailService.MailSenderAsync(LoginHandler.SelectedUser.User_Email, "Kvittering på booking af tavletid", $"Du har booked tavlen i rummet {Reference.SelectedBooking.RoomName}" +
                                                            $"d. {Reference.SelectedBooking.Date.ToString("dd/MM/yyyy")} " +
                                                            $"mellem {new DateTime(myNewTavleBooking.Time_start.Ticks).ToString("HH:mm")} og {new DateTime(myNewTavleBooking.Time_end.Ticks).ToString("HH:mm")}.", true);
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            DialogHandler.Dialog("Denne tid modstrider en anden tavle booking\nVælg venligst en tidligere eller senere tid", "Modstridende tider");
                        }
                    }
                    else
                    {
                        // INSERT
                        if (await DialogHandler.GenericYesNoDialog("Er du sikker på du vil booke denne tavletid?\nKvittering på tavlen vil blive tilsendt via mail", "Book Book Tavle?", "Ja", "Fortryd"))
                        {
                            await PersistancyService.SaveInsertAsJsonAsync(myNewTavleBooking, "TavleBookings");

                            MailService.MailSenderAsync(LoginHandler.SelectedUser.User_Email, "Kvittering på booking af tavletid", $"Du har booked tavlen i rummet {Reference.SelectedBooking.RoomName}" +
                                                        $"d. {Reference.SelectedBooking.Date.ToString("dd/MM/yyyy")} " +
                                                        $"mellem {new DateTime(myNewTavleBooking.Time_start.Ticks).ToString("HH:mm")} og {new DateTime(myNewTavleBooking.Time_end.Ticks).ToString("HH:mm")}.", true);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            RefreshLists();
            Reference.SelectedBooking = tempSelectedBooking;
        }
Пример #6
0
        /// <summary>
        /// This method books the selected room again tomorrow, if that is possible.
        /// </summary>
        public static async Task BookAgainTomorrowMethodAsync()
        {
            // Retrieves the day after the selected booking date
            DateTime tomorrow = Reference.SelectedBooking.Date.AddDays(1);
            // The copied booking that needs to be inserted into the database with the updated date.
            Booking updatedBooking = new Booking()
            {
                User_Id    = Reference.SelectedUser.User_Id,
                Room_Id    = Reference.SelectedBooking.Room_Id,
                Date       = tomorrow,
                Time_start = Reference.SelectedBooking.BookingStart,
                Time_end   = Reference.SelectedBooking.BookingEnd
            };
            // This object will be set to the returned booking that gets posted to the database and later used in the AllBookingsView object
            Booking returnedObj = null;
            // This object is the view object that gets added to the singleton, to that the view will be updated.-
            AllBookingsView viewToAdd = null;
            // Checks how many instances there is of this selectedbooking's specific room.
            var howManyOfThisRoomTomorrowQuery = (from b in AllBookingsViewCatalogSingleton.Instance.AllBookings
                                                  select b).Where(x => Reference.SelectedBooking.Room_Id == x.Room_Id && x.Date == tomorrow).ToList();

            if (howManyOfThisRoomTomorrowQuery.Count == 2)
            {
                // checks if there is any instances that overlaps the selectedbookings's time
                var checkTime = (from b in howManyOfThisRoomTomorrowQuery
                                 select b).Where(x => Reference.SelectedBooking.BookingStart > x.BookingStart && Reference.SelectedBooking.BookingStart <x.BookingEnd || Reference.SelectedBooking.BookingEnd> x.BookingStart && Reference.SelectedBooking.BookingEnd < x.BookingEnd).ToList();
                // If 0 or less
                if (checkTime.Count < 1)
                {
                    var result = await DialogHandler.GenericYesNoDialog("Er du sikker på du vil booke dette rum igen imorgen samme tid?\nKvittering på bookning af det nye rum vil blive tilsendt via mail", "Book igen imorgen?", "Ja", "Fortryd");

                    if (result)
                    {
                        // Inserts the selectedbooking into the database and updates the singleton
                        returnedObj = await PersistancyService.SaveInsertAsJsonAsync(updatedBooking, "Bookings");

                        MailService.MailSenderAsync(LoginHandler.SelectedUser.User_Email, "Kvittering på booking af rum", $"Du har booked rummet {Reference.SelectedBooking.RoomName} igen for " +
                                                    $"d. {returnedObj.Date.ToString("dd/MM/yyyy")} " +
                                                    $"mellem {new DateTime(returnedObj.Time_start.Ticks).ToString("HH:mm")} og {new DateTime(returnedObj.Time_end.Ticks).ToString("HH:mm")}.", true);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    // Error message that displays if there already exists a booking in the database that overlaps with the selectedbooking on the day after the selectedbooking date
                    DialogHandler.Dialog("Denne booking kan ikke bookes imorgen\nda den overlapper eksisterende bookninger", "Overlappende Bookninger");
                }
            }
            else
            {
                var result = await DialogHandler.GenericYesNoDialog("Er du sikker på du vil booke dette rum igen imorgen samme tid?\nKvittering på bookning af det nye rum vil blive tilsendt via mail", "Book igen imorgen?", "Ja", "Fortryd");

                if (result)
                {
                    // Inserts the selectedbooking into the database and updates the singleton
                    returnedObj = await PersistancyService.SaveInsertAsJsonAsync(updatedBooking, "Bookings");

                    MailService.MailSenderAsync(LoginHandler.SelectedUser.User_Email, "Kvittering på booking af rum", $"Du har booked rummet {Reference.SelectedBooking.RoomName} igen for " +
                                                $"d. {returnedObj.Date.ToString("dd/MM/yyyy")} " +
                                                $"mellem {new DateTime(returnedObj.Time_start.Ticks).ToString("HH:mm")} og {new DateTime(returnedObj.Time_end.Ticks).ToString("HH:mm")}.", true);
                }
                else
                {
                    return;
                }
            }
            if (returnedObj != null)
            {
                viewToAdd = new AllBookingsView()
                {
                    RoomName        = Reference.SelectedBooking.RoomName,
                    Date            = tomorrow,
                    Booking_Id      = returnedObj.Booking_Id,
                    BookingStart    = Reference.SelectedBooking.BookingStart,
                    BookingEnd      = Reference.SelectedBooking.BookingEnd,
                    Room_Id         = Reference.SelectedBooking.Room_Id,
                    Floor           = Reference.SelectedBooking.Floor,
                    No              = Reference.SelectedBooking.No,
                    Name            = Reference.SelectedBooking.Name,
                    Building_Letter = Reference.SelectedBooking.Building_Letter,
                    Type            = Reference.SelectedBooking.Type,
                    User_Id         = Reference.SelectedBooking.User_Id
                };
                // Adds the viewToAdd object, to the singleton
                Reference.AllUserBookingsFromSingleton.Add(viewToAdd);
                // Refreshes the singleton, and re-queries the bookings for the selected user
                RefreshLists();
                // sets the selected booking to the newly added booking
                Reference.SelectedBooking = Reference.AllUserBookingsFromSingleton.First();
            }
        }