Example #1
0
        public async Task <IActionResult> Create([Bind("ID,ResourceId,EventColor,Start,End,Title,RoomID,IsFullDay,Days,Weeks,Email,StudentNumbers")] Events events)
        {
            ViewBag.TodayDate = DateTime.Today.ToLongDateString();
            ViewBag.Roomlist  = new SelectList(or.GetOrderedRooms(), "ID", "Title");

            try
            {
                //get user details save to db
                string   UserEmail = User.Identity.Name;
                string[] details   = UserEmail.Split('@');
                //pass it back to the event in the SchedularCustom.js
                events.Name  = details[0];
                events.Email = UserEmail;
            }
            catch (Exception)
            {
                //person not logged in
                events.Name  = "Not Logged In";
                events.Email = "Not Logged In";
            }


            //is the start date older than the end date?
            if (ModelState.IsValid)
            {
                //check if there is a fullday or repeating weeks or days
                if (events.IsFullDay || events.Days > 0 || events.Weeks > 0)
                {
                    foreach (var booking in DayWeeksAllDayMods.EventCalc(events))
                    {
                        _context.Add(booking);
                    }
                }
                //pass through the event and look for clashes where its the same room after today
                DayWeeksAllDayMods.DoTheDatesOverlap(_context.Events.Where(e => e.ResourceId == events.ResourceId && e.End > DateTime.Now).ToList(), events);

                //We have a clash
                if (DayWeeksAllDayMods.WeHaveAClash == true)
                {
                    return(RedirectToAction("Clash"));
                }
                else
                {//we dont have a clash
                    _context.Add(events);
                    await _context.SaveChangesAsync();

                    return(View());
                }
            }
            else
            {
                //if model is not valid return view - have to refresh context
                ViewBag.Roomlist = new SelectList(or.GetOrderedRooms(), "ID", "Title");
                return(View());
            }
        }
Example #2
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" }));
            }
        }
Example #3
0
        public async Task <IActionResult> Create(AppartmentViewModel appartment)
        {
            if (appartment.Photo != null)
            {
                BlobContainerClient containerClient = _blobService.GetBlobContainerClient("home");
                Stream          stream      = appartment.Photo.OpenReadStream();
                string          fileName    = $"{Guid.NewGuid().ToString()}{appartment.Photo.FileName}";
                BlobContentInfo blobContent = await containerClient.UploadBlobAsync(fileName, stream);

                BlobClient blobClient = containerClient.GetBlobClient(fileName);
                string     url        = blobClient.Uri.AbsoluteUri;
                Appartment newAppart  = new Appartment();
                newAppart.Title       = appartment.Title;
                newAppart.Description = appartment.Description;
                newAppart.Owner       = appartment.Owner;
                newAppart.Price       = appartment.Price;
                newAppart.Photo       = fileName;
                newAppart.PhotoPath   = url;
                _context.Add(newAppart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appartment));
        }
Example #4
0
        public async Task <IActionResult> Create
            ([Bind("AppointmentID,AppointmentDate,CustomerID,StaffID")] Appointment appointment)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(appointment);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            // ViewData["CustomerID"] = new SelectList(_context.Customers, "ID", "LastName", appointment.CustomerID);
            // ViewData["StaffID"] = new SelectList(_context.Staffs, "ID", "LastName", appointment.StaffID);
            return(View(appointment));
        }
Example #5
0
        public async Task <IActionResult> Post(Book developer)
        {
            _context.Add(developer);
            await _context.SaveChangesAsync();

            return(Ok(developer.BookId));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("Id,BookingId,SeatNumber")] Seat seat)
        {
            if (ModelState.IsValid)
            {
                DatabaseManager.NumberOfSeats = DatabaseManager.NumberOfSeats - 1;
            }



            {
                _context.Add(seat);
                await _context.SaveChangesAsync();

                if (DatabaseManager.NumberOfSeats <= 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction(nameof(Create)));
                }
            }

            return(View(seat));
        }
Example #7
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" }));
            }
        }
Example #8
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));
        }
Example #9
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Telephone")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(staff));
        }
        public async Task <IActionResult> Create([Bind("BookingID,CustomerID,TableID,BookingDate,BookedFrom,BookedUntil,PartySize")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(booking));
        }
Example #11
0
        public async Task <IActionResult> Create([Bind("Id,Name,ShowId,Date")] Performances performances)
        {
            if (ModelState.IsValid)
            {
                _context.Add(performances);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(performances));
        }
        public async Task <IActionResult> Create([Bind("CustomerID,FirstName,LastName,Mobile,Email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Example #13
0
        public async Task <IActionResult> Create([Bind("Id,Name,EndDate,FullPrice,ConcessionPrice")] Shows shows)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shows);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shows));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Department,BookingCount")] StaffNames staffNames)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffNames);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staffNames));
        }
Example #15
0
        public async Task <IActionResult> Create([Bind("Idhotel,NomeHotel,NumEstrelas,Morada,Localidade,CodPostal,Pais,QuantidadeQuartos,Descricao")] Hoteis hoteis)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hoteis);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hoteis));
        }
        public async Task <IActionResult> Create([Bind("IdtipoPagamento,Designacao")] TipoPagamento tipoPagamento)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tipoPagamento);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoPagamento));
        }
Example #17
0
        public async Task <IActionResult> Create([Bind("Idcliente,Nome,Sobrenome,Email,Contacto,Morada,Localidade,CodPostal,Cc,DataNasc")] Clientes clientes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clientes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientes));
        }
Example #18
0
        public async Task <IActionResult> Create([Bind("TableID,TableNumber")] Table table)
        {
            if (ModelState.IsValid)
            {
                _context.Add(table);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(table));
        }
Example #19
0
 private static void InsertBarcode(IList <string> barcodes, int bookId)
 {
     foreach (var barcode in barcodes)
     {
         using var db2 = new BookingContext();
         db2.Add(new BooksCopies()
         {
             Barcode = barcode, BookId = bookId, Registered = System.DateTime.Now
         });
         db2.SaveChanges();
     }
 }
Example #20
0
        public async Task <IActionResult> Create([Bind("CodPagamento,IdtipoPagamento,NomeTitular,NumCartao,DataValidadeCartao,Cvv,Descricao")] Pagamento pagamento)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pagamento);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdtipoPagamento"] = new SelectList(_context.TipoPagamento, "IdtipoPagamento", "Designacao", pagamento.IdtipoPagamento);
            return(View(pagamento));
        }
        public async Task <IActionResult> Create([Bind("Idespecificacao,IdtipoQuarto,Descricao")] EspecificacoesQuarto especificacoesQuarto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(especificacoesQuarto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdtipoQuarto"] = new SelectList(_context.TipoQuarto, "IdtipoQuarto", "Descricao", especificacoesQuarto.IdtipoQuarto);
            return(View(especificacoesQuarto));
        }
        public async Task <IActionResult> Create([Bind("Idservicos,Idhotel,Descricao")] ServicosHotel servicosHotel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(servicosHotel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idhotel"] = new SelectList(_context.Hoteis, "Idhotel", "CodPostal", servicosHotel.Idhotel);
            return(View(servicosHotel));
        }
Example #23
0
        public async Task <IActionResult> Create([Bind("Idregime,Idhotel,TipoRegime")] Regimes regimes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(regimes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idhotel"] = new SelectList(_context.Hoteis, "Idhotel", "CodPostal", regimes.Idhotel);
            return(View(regimes));
        }
        public async Task <IActionResult> Create([Bind("IdtipoQuarto,Idhotel,Capacidade,Inventario,Descricao,Imagem")] TipoQuarto tipoQuarto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tipoQuarto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idhotel"] = new SelectList(_context.Hoteis, "Idhotel", "CodPostal", tipoQuarto.Idhotel);
            return(View(tipoQuarto));
        }
Example #25
0
        public async Task <IActionResult> Create([Bind("Idregime,IdtipoQuarto,Data,Preco")] Precario precario)
        {
            if (ModelState.IsValid)
            {
                _context.Add(precario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idregime"]     = new SelectList(_context.Regimes, "Idregime", "TipoRegime", precario.Idregime);
            ViewData["IdtipoQuarto"] = new SelectList(_context.TipoQuarto, "IdtipoQuarto", "Descricao", precario.IdtipoQuarto);
            return(View(precario));
        }
        public async Task <IActionResult> Create([Bind("Idreserva,Idhotel,Idcliente,Idregime,IdtipoQuarto,CodPagamento,QuantAdultos,QuantCriancas,CheckIn,CheckOut")] Reservas reservas)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservas);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CodPagamento"] = new SelectList(_context.Pagamento, "CodPagamento", "DataValidadeCartao", reservas.CodPagamento);
            ViewData["Idcliente"]    = new SelectList(_context.Clientes, "Idcliente", "Cc", reservas.Idcliente);
            ViewData["Idhotel"]      = new SelectList(_context.Hoteis, "Idhotel", "CodPostal", reservas.Idhotel);
            ViewData["Idregime"]     = new SelectList(_context.Regimes, "Idregime", "TipoRegime", reservas.Idregime);
            ViewData["IdtipoQuarto"] = new SelectList(_context.TipoQuarto, "IdtipoQuarto", "Descricao", reservas.IdtipoQuarto);
            return(View(reservas));
        }
        public async Task SaveEventRequest <T>(Guid id)
        {
            // ** saving event...
            _logger.CreateLogger <EventRequestManager>().LogInformation("----- Saving event for idempotency of integration event: {IntegrationEventId} at {AppName}", id, Program.AppName);

            var request = new EventRequest()
            {
                Id   = id,
                Name = typeof(T).Name,
                Time = DateTime.UtcNow
            };

            _context.Add(request);

            await _context.SaveChangesAsync();

            //throw new Exception($"Request with {id} already exists");
        }
        public async Task<IActionResult> Create([Bind("Id,PerformanceId,Name,Email,NumberFullPrice,NumberConcessionPrice,StoreEmail,TotalCost")] Booking booking)
        {
            BookingSystemDTO bookingsystemdto = new BookingSystemDTO();
            myBooking myShows = new myBooking();



            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();
                return RedirectToAction("Details", new {booking.Id });

            }

           

            return View(booking);
        }
        public IActionResult Reserve(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Booking"));
                }

                using var db = new BookingContext();

                var total = db.ReservedBook.Count(x => x.BookId == id && x.ReturnedDate == null);

                var isBookAvailable = (total - db.ReservedBook.Count(x => x.BookId == id && x.ReturnedDate == null)) >= 1;

                if (isBookAvailable)
                {
                    if (db.ReservedBook.Count(x => x.BookId == id && x.UserId == UserID) < MAX_COPIES)
                    {
                        db.Add(new ReservedBook()
                        {
                            BookId       = id,
                            UserId       = UserID,
                            ReservedDate = DateTime.Now
                        });
                        db.SaveChanges();
                        return(RedirectToAction("Index", "Booking", new { msg = "reserved" }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Booking", new { error = "tooMany" }));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Booking", new { error = "unavailable" }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Booking", new { error = "error" }));
            }
        }
        public async Task <IActionResult> Create
            ([Bind("ID,FirstName,LastName,Telephone")] Customer customer)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(customer);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(customer));
        }