public IHttpActionResult PutBooking(int id, Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != booking.BookingID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <ActionResult <Tag> > Add([FromBody] CreateTagRequest request)
        {
            var newTag = new Tag()
            {
                Name = request.Name,
            };
            List <CategoryTag> categoryTags = new List <CategoryTag>();

            if (request.CategoryNames != null)
            {
                foreach (var item in request.CategoryNames)
                {
                    var categoryTag = new CategoryTag();
                    categoryTag.TagId      = newTag.Id;
                    categoryTag.CategoryId = _context.Categories.FirstOrDefault(category => category.Name == item).Id;
                    categoryTags.Add(categoryTag);
                }
            }

            newTag.CategoryTags = categoryTags;
            _context.Tags.Add(newTag);
            _context.SaveChanges();

            return(Ok(newTag));
        }
示例#3
0
        public IActionResult CreateBookings([FromBody] Booking[] bookings)
        {
            if (bookings.Count() > 4)
            {
                return(null);
            }

            foreach (Booking booking in bookings)
            {
                //Retrieve the seat from the context, if it is not already booked, book it
                Seat existingSeat = _context.Seats.FirstOrDefault(seat => seat.Label == booking.Seat);

                //Null check catches seats that should not exist
                if (existingSeat != null && existingSeat.BookingId == 0)
                {
                    //Tried adding a Unique Constraint on the table to prevent duplicates on Name and Email, doesn't seem to have worked though
                    //So using this to check for existing combinations
                    var existingNameAndEmail = _context.Bookings.Where(existingBooking => existingBooking.Name == booking.Name && existingBooking.Email == booking.Email);
                    if (existingNameAndEmail.Count() == 0)
                    {
                        _context.Add(booking);
                        _context.SaveChanges();

                        //Save the new booking id to the Seat
                        int id = booking.ID;
                        existingSeat.BookingId = id;
                        _context.SaveChanges();
                    }
                }
            }
            return(CreatedAtRoute("Create Bookings", new { bookings = bookings }, bookings));
        }
示例#4
0
        public IHttpActionResult PutAttendee(int id, Attendee attendee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attendee.AttendeeID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutLogin(int id, Login login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != login.StudentID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#6
0
        public IHttpActionResult PutRoom(int id, Room room)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != room.RommID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult <Booking> Create(Booking item)
        {
            _context.Bookings.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetBooking", new { id = item.id }, item));
        }
        public ActionResult <CapacityProvider> Create(CapacityProvider item)
        {
            _context.CapacityProviders.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetCapacityProvider", new { id = item.id }, item));
        }
示例#9
0
        public ActionResult CreatePost([Bind(Include = "MeetingReference, RoomId, Date, Start_DateTime, End_DateTime, UserId")] Booking booking)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //make sure room is still free
                    foreach (Booking b in db.Bookings)
                    {
                        if (!b.IsValidBooking(booking))
                        {
                            ModelState.AddModelError("", "This room is not available any longer for booking. Please try to make another booking.");
                            PopulateStartTimeDropDownList(booking.Start_DateTime);
                            PopulateEndTimeDropDownList(booking.End_DateTime);
                            return(View("Create", new { Date = booking.Date }));
                        }
                    }
                    db.Bookings.Add(booking);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("", "Sorry, there was an error. Please try again.");
                return(RedirectToAction("Create"));
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes. Please try again, and if the problem persists, contact your system admistrator");
                return(RedirectToAction("Create"));
            }
        }
示例#10
0
        public int BookMovieInMultiplex(BookingDto bookingDto)
        {
            Booking newBooking = new Booking {
                MovieId = bookingDto.MovieId, Amount = bookingDto.Amount, SeatNo = bookingDto.SeatNo, UserId = bookingDto.UserId, DateToPresent = Convert.ToDateTime(bookingDto.DateToPresent)
            };

            _bookingContext.Bookings.Add(newBooking);
            _bookingContext.SaveChanges();
            return(newBooking.Id);
        }
示例#11
0
        public IActionResult FirstTime(string userName, string adminEmail, string adminPassword, string repeatPassword, string port, string max, string email, string host, string password)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("FirstTime", "Home"));
                }

                if (adminPassword != repeatPassword)
                {
                    return(RedirectToAction("FirstTime", "Home", new { msg = "wrongPasswords" }));
                }

                if (!string.IsNullOrEmpty(email) && (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(port)))
                {
                    return(RedirectToAction("FirstTime", "Home", new { error = "wrongEmailSettings" }));
                }

                using var db = new BookingContext();

                var user = new Users()
                {
                    Username = userName,
                    Email    = adminEmail,
                    Password = Encryption.Encrypt(adminPassword),
                    Role     = 0
                };
                db.Add(user);
                db.SaveChanges();

                int?intPort = int.TryParse(port, out var tempVal) ? tempVal : (int?)null;

                var settings = new Settings
                {
                    Port     = intPort,
                    Email    = email,
                    MaxTime  = int.Parse(max),
                    MailHost = host
                };

                if (!string.IsNullOrEmpty(password))
                {
                    settings.PasswordHost = DB.EncryptionMails.EncryptString(SettingsController.PASS_KEY, password);
                }
                db.Add(settings);
                db.SaveChanges();

                return(RedirectToAction("Index", "Home", new { msg = "userCreated" }));
            }
            catch
            {
                return(RedirectToAction("FirstTime", "Home", new { error = "error" }));
            }
        }
        public ActionResult Create([Bind(Include = "Id,ClientName,Phone,Email,Insurance")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
示例#13
0
        public ActionResult Create([Bind(Include = "Booking_id,booking_title,start_time,end_time,participants,note,room_id,users_id")] Bookings bookings)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(bookings);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bookings));
        }
示例#14
0
        public ActionResult Create([Bind(Include = "Id,RoomNumber,CapacityOfPeople")] Room room)
        {
            if (ModelState.IsValid)
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(room));
        }
示例#15
0
        public ActionResult Create([Bind(Include = "TableId,TableNumber,TableCapacity")] TableModel tableModel)
        {
            if (ModelState.IsValid)
            {
                db.Tables.Add(tableModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tableModel));
        }
示例#16
0
        public ActionResult Create([Bind(Include = "CustomerId,FirstName,LastName,Telephone,Email")] CustomerModel customerModel)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customerModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerId = new SelectList(db.Bookings, "BookingId", "BookingComments", customerModel.CustomerId);
            return(View(customerModel));
        }
        public ActionResult Create([Bind(Include = "BookingId,BookingDateTime,Duration,PartySize,TableAllocation,BookingComments")] BookingModel bookingModel)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(bookingModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BookingId = new SelectList(db.Customers, "CustomerId", "FirstName", bookingModel.BookingId);
            ViewBag.BookingId = new SelectList(db.Tables, "TableId", "TableId", bookingModel.BookingId);
            return(View(bookingModel));
        }
        public IActionResult Post([FromBody] OpcionalDto opcionalRequest)
        {
            var opcional           = MapearDtoParaDominio(opcionalRequest);
            var opcionalCadastrado = opcionalRepository.SalvarOpcional(opcional);

            var mensagem = opcionalService.Validar(opcional);

            if (mensagem.Any())
            {
                return(BadRequest(mensagem));
            }

            contexto.SaveChanges();
            return(CreatedAtRoute("GetOpcional", new { id = opcional.Id }, opcional));
        }
        public IActionResult Post([FromBody] SuiteDto suiteRequest)
        {
            var suite           = MapearDtoParaDominio(suiteRequest);
            var suiteCadastrada = suiteRepository.SalvarSuite(suite);

            var mensagem = suiteService.Validar(suiteCadastrada);

            if (mensagem.Any())
            {
                return(BadRequest(mensagem));
            }

            contexto.SaveChanges();
            return(CreatedAtRoute("GetSuite", new { id = suite.Id }, suite));
        }
示例#20
0
        //Can be rented could be a solution to the point of a stolen book
        private static void UpdateBook(int id, string book, string author, int?year, IList <string> barcodes, BookingContext db)
        {
            var bookData = db.Books.FirstOrDefault(x => x.BookId == id);

            bookData.Name            = book;
            bookData.Author          = author;
            bookData.PublicationYear = year;

            db.Update(bookData);
            db.SaveChanges();

            var currentBarcodes = db.BooksCopies.Where(x => x.BookId == id).Select(x => x.Barcode).ToList();

            var newBarcodes = barcodes.Except(currentBarcodes).ToList();

            InsertBarcode(newBarcodes, id);

            var removedBarcodes = currentBarcodes.Except(barcodes).ToList();

            foreach (var barcode in removedBarcodes)
            {
                var booksCopiesId = db.BooksCopies.FirstOrDefault(x => x.Barcode == barcode).BooksCopiesId;
                if (db.ReservedBook.Count(x => x.BooksCopiesId == booksCopiesId) == 0)
                {
                    using var db2 = new BookingContext();
                    db2.Remove(new BooksCopies {
                        BooksCopiesId = booksCopiesId
                    });
                    db2.SaveChanges();
                }
            }
        }
示例#21
0
        public IHttpActionResult Post([FromBody] TimeBooking booking)
        {
            if (!isBookingHaveEverythingExceptUsername(booking))
            {
                return(BadRequest(ModelState));
            }

            try
            {
                if (!String.IsNullOrEmpty(booking.UserName) && HttpContext.Current.User.IsInRole("Admin"))
                {
                    using (var con = new BookingContext())
                    {
                        con.Bookings.Add(booking);
                        con.SaveChanges();
                    }
                }
                else
                {
                    using (var con = new BookingContext())
                    {
                        booking.UserName = HttpContext.Current.User.Identity.Name;
                        con.Bookings.Add(booking);
                        con.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
            MyHub.RequestUpdate();
            return(Ok("You have successfully saved the booking."));
        }
示例#22
0
        public IHttpActionResult Delete(int bookingID)
        {
            if (!CheckIfAuthorized(bookingID))
            {
                return(BadRequest("You are not authorized to delete bookings for other users."));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    using (var con = new BookingContext())
                    {
                        var booking = con.Bookings.Where(b => b.Id == bookingID).FirstOrDefault();
                        con.Bookings.Remove(booking);
                        con.SaveChanges();
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }

            catch
            {
                return(InternalServerError());
            }
            MyHub.RequestUpdate();
            return(Ok("You have successfully deleted the booking."));
        }
示例#23
0
        public IActionResult ReturnedBook(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Library"));
                }

                using var db = new BookingContext();

                var reservedBook = db.ReservedBook.FirstOrDefault(x => x.ReservedBookId == id);

                reservedBook.ReturnedDate = DateTime.Now;

                db.Update(reservedBook);

                db.SaveChanges();

                return(RedirectToAction("Index", "Library", new { msg = "returned" }));
            }
            catch
            {
                return(RedirectToAction("Index", "Library", new { error = "error" }));
            }
        }
示例#24
0
        public IActionResult CancelReservation(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Library"));
                }

                using var db = new BookingContext();

                //Uncomment it to send emails
                //var reservedBook = db.ReservedBook.FirstOrDefault(x => x.ReservedBookId == id);
                //var email = db.Users.FirstOrDefault(x => x.UserId == reservedBook.UserId).Email;
                //var book = db.Books.FirstOrDefault(x => x.BookId == reservedBook.BookId).Name;
                //MailLibrary.MailNotifications.SendEmail(email, SUBJECT_CANCEL, string.Format(BODY_CANCEL, book));

                db.Remove(new ReservedBook()
                {
                    ReservedBookId = id
                });
                db.SaveChanges();

                return(RedirectToAction("Index", "Library", new { msg = "reservationCanceled" }));
            }
            catch
            {
                return(RedirectToAction("Index", "Library", new { error = "error" }));
            }
        }
示例#25
0
        public IActionResult DeleteBook(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Library"));
                }

                using var db = new BookingContext();

                if (db.ReservedBook.Count(x => x.BookId == id) == 0)
                {
                    db.Remove(new Books()
                    {
                        BookId = id
                    });
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Library", new { msg = "bookDeleted" }));
                }
                return(RedirectToAction("Index", "Library", new { error = "reserved" }));
            }
            catch
            {
                return(RedirectToAction("Index", "Library", new { error = "error" }));
            }
        }
示例#26
0
        public IActionResult Index(string username, string email, string password, string SelectedRole)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Library"));
                }

                using var db = new BookingContext();

                if (db.Users.Count(x => x.Email == email) > 0)
                {
                    return(RedirectToAction("Update", "User", new { error = "sameEmail" }));
                }
                else if (db.Users.Count(x => x.Username == username) == 0)
                {
                    _ = db.Add(new Users()
                    {
                        Username = username, Email = email, Registered = DateTime.Now, Role = int.Parse(SelectedRole), Password = Encryption.Encrypt(password)
                    });
                    _ = db.SaveChanges();

                    return(RedirectToAction("Index", "User", new { msg = "created" }));
                }
                else
                {
                    return(RedirectToAction("Index", "User", new { error = "exist" }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "User", new { error = "error" }));
            }
        }
示例#27
0
        private void AddNewBookingsFromGoogleCaledar(DateTime startDate)
        {
            var googleCalendarEvents = GetEventRequest(startDate);
            var localEvents          = GetEventsFromLocalBase().ToList();
            var newbookings          = new List <BookingModel>();

            foreach (var ev in googleCalendarEvents)
            {
                if (localEvents.Where(x => x.TimeOfVisit == ev.Start.DateTime && x.EndTime == ev.End.DateTime)
                    .IsNullOrEmpty())
                {
                    newbookings.Add(new BookingModel
                    {
                        Customer    = null,
                        TimeOfVisit = ev.Start.DateTime.GetValueOrDefault(),
                        EndTime     = ev.End.DateTime.GetValueOrDefault(),
                    });
                }
            }
            foreach (var book in newbookings)
            {
                db.Bookings.Add(book);
                db.SaveChanges();
            }
        }
示例#28
0
        public City Create(City city)
        {
            var cities = context.City.Add(city);

            context.SaveChanges();
            return(cities);
        }
        public IActionResult DeletarPorIdUsuario(int id)
        {
            var usuario = usuarioRepository.ObterUsuarioPorEmail(User.Identity.Name);

            var reserva = reservaRepository.DeletarReservaPorUsuario(usuario, id);

            var mensagem = reservaService.Validar(reserva);

            if (mensagem.Any())
            {
                return(BadRequest(mensagem));
            }

            contexto.SaveChanges();

            return(Ok());
        }
示例#30
0
        public void BookingTest()
        {
            using (var db = new BookingContext())
            {
                var myHotel   = "Flash Hotel";
                var myAirline = "AirAsia";

                var hotelId      = 0;
                var hotelName    = "";
                var flightId     = 0;
                var flightName   = "";
                var returnFlight = "";

                foreach (var hotel in db.Hotels)
                {
                    if (hotel.Name.Equals(myHotel))
                    {
                        hotelId   = hotel.Id;
                        hotelName = hotel.Name;
                    }
                }

                foreach (var flight in db.Flights)
                {
                    if (flight.Airline.Equals(myAirline))
                    {
                        flightId     = flight.Id;
                        flightName   = flight.Airline;
                        returnFlight = flight.Return_flight.ToString();
                    }
                }

                if (flightId != 0 && hotelId != 0)
                {
                    db.Bookings.Add(new Booking()
                    {
                        Hotel_id = hotelId, Flight_id = flightId
                    });
                    db.SaveChanges();

                    foreach (var booking in db.Bookings)
                    {
                        Console.WriteLine("Booking Id : " + booking.Id);
                        Console.WriteLine("Hotel : " + hotelName);
                        Console.WriteLine("Flight : " + flightName);
                        Console.WriteLine("Return Flight : " + returnFlight);
                    }
                }
                else
                {
                    Console.WriteLine("Hotel or Flight name incorrect!");
                }
            }
        }