public static void GenerateAccount(BookingDBContext context, Account newAccount)
        {
            // Create a new user record
            var newUser = new Users();

            // Generate a new salt
            var salt = Salter.Shake();

            // Hash the password and the salt
            var hashedPass = Hasher.Hash(newAccount.Password + salt);

            // Get the role id from the database
            var roleId = context.Roles.First(r => r.RoleName == newAccount.Role).RoleId;

            // Fill in the fields
            newUser.UserName       = newAccount.Username;
            newUser.HashedPassword = hashedPass;
            newUser.Salt           = salt;
            newUser.RoleId         = roleId;

            if (newAccount.Email != null)
            {
                newUser.Email = newAccount.Email;
            }

            // Add the user to the database
            context.Users.Add(newUser);

            // Save to the database
            context.SaveChanges();
        }
        public static bool ValidatePassword(BookingDBContext context, string username, string password)
        {
            // Get the user id from the database
            var userId = GetUserId(context, username);

            // Check there's a valid user id
            if (userId == -1)
            {
                return(false);
            }

            // Get the hashed password from the database
            var hashedPass = GetHashedPass(context, userId);

            // Get the salt from the database
            var salt = GetSalt(context, userId);

            // Hash what the user input
            var newHashedPass = Hasher.Hash(password + salt);

            // If the passwords match
            if (newHashedPass == hashedPass)
            {
                return(true);
            }

            return(false);
        }
        static void LoadData()
        {
            // using(var db = new BookingDBContext())
            // {
            //   db.Bookings.Add(new Booking{booking_id = 1, Name = "Table One Booked", Date = "24/3/2019"});

            using (var context = new BookingDBContext())
            {
                // iBookingRepository IBookingRepository;
                var bookingRepository = new BookingRepository(context);
                var booking           = new Booking {
                    booking_id = 1, Name = "Table One Booked", Date = "24/3/2019"
                };
                //  IBookingRepository.save();
                bookingRepository.InsertBooking(booking);
                bookingRepository.Save();
                context.Bookings.Add(booking);
                context.SaveChanges();


                // db.Bookings.Add(new Booking{Name = "Table One Booked"});
                // db.SaveChanges();
                // var count = db.SaveChanges();
            }
        }
示例#4
0
        public UserController(BookingDBContext context, IConfiguration config)
        {
            _context = context;
            _config  = config;
            var emailConfig = this._config.GetSection("Email");

            emailUserName = emailConfig["Username"].ToString();
            emailPassword = emailConfig["Password"].ToString();
        }
        // Gets the salt from the database for the user
        private static string GetSalt(BookingDBContext context, int userId)
        {
            // Get all the users
            var allUsers = context.Users.ToList();

            // Get the user record
            var user = allUsers.First(u => u.UserId == userId);

            // Return the salt
            return(user.Salt);
        }
        // This gets the hashed password for a user from the database
        private static string GetHashedPass(BookingDBContext context, int userId)
        {
            // Get all the users
            var allUsers = context.Users.ToList();

            // Get the user record
            var user = allUsers.First(u => u.UserId == userId);

            // Return the hashed password for that user
            return(user.HashedPassword);
        }
        // Gets the userid from the database from the username
        private static int GetUserId(BookingDBContext context, string username)
        {
            // Get all the users from the database
            var allUsers = context.Users.ToList();

            // If there aren't any users with that user id, return -1
            if (!context.Users.Any(u => u.UserName == username))
            {
                return(-1);
            }

            // Get the user record
            var user = allUsers.First(u => u.UserName == username);

            // Return the user id
            return(user.UserId);
        }
        // Authorise a user
        public bool Authorise(RolesEnum role, BookingDBContext context)
        {
            // If there isn't a role
            if (_httpContextAccessor.HttpContext.Session.GetString("Role") == null || _httpContextAccessor.HttpContext.Session.GetString("Role") == "")
            {
                return(false);
            }

            // Get the current role from the session
            var currentRole = _httpContextAccessor.HttpContext.Session.GetString("Role");

            // Convert the role enum to and int and check if it's higher or equal than the minimum
            if ((int)role >= context.Roles.First(n => n.RoleName == currentRole).RoleId)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
 public BookingsController(BookingDBContext context)
 {
     _context          = context;
     _bookingValidator = new BookingValidator(_context);
 }
 public BookingRepository(BookingDBContext context)
 {
     this.context = context;
 }
 public ProjectController(BookingDBContext context, AuthoriseUser auth)
 {
     _context = context; // The database context object
     _auth    = auth;    // Authentication service
 }
示例#12
0
 public RoomsController(BookingDBContext context)
 {
     _context = context;
 }
 public BroadcastSystemController(BookingDBContext context, AuthoriseUser auth)
 {
     _context = context; // Database context object
     _auth    = auth;    // Authentication service
 }
示例#14
0
 public ImagesController(BookingDBContext context)
 {
     _context = context;
 }
        public ActionResult PDF(int id)
        {
            // This code is for export Database data to PDF file
            string fileName = Guid.NewGuid() + ".pdf";
            string filePath = System.IO.Path.Combine(Server.MapPath("~/PDFFiles"), fileName);

            Document doc = new Document(PageSize.A4.Rotate(), 2, 2, 2, 2);
            // Create paragraph for show in PDF file header
            Paragraph p = new Paragraph("Export Database data to PDF file in ASP.NET");
            //p.SetAlignment("center");

            //try
            //{
            PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
            //Create table here for write database data
            PdfPTable pdfTab = new PdfPTable(8); // here 7 is no of column
            pdfTab.HorizontalAlignment = 1; // 0- Left, 1- Center, 2- right
            pdfTab.SpacingBefore = 20f;
            pdfTab.SpacingAfter = 20f;

            var data = new Booking();
            using (BookingDBContext dc = new BookingDBContext())
            {
                data = dc.Bookings.First(x => x.ID == id);
            }

            pdfTab.AddCell("ID");
            pdfTab.AddCell("Guest Name");
            pdfTab.AddCell("Address");
            pdfTab.AddCell("City");
            pdfTab.AddCell("State");
            pdfTab.AddCell("Date In");
            pdfTab.AddCell("Date Out");
            pdfTab.AddCell("Balance");

            pdfTab.AddCell(data.ID.ToString());
            pdfTab.AddCell(data.GuestName);
            pdfTab.AddCell(data.Address);
            pdfTab.AddCell(data.City);
            pdfTab.AddCell(data.State);
            pdfTab.AddCell(data.DateIn.ToString("MM/dd/yyyy"));
            pdfTab.AddCell(data.DateOut.ToString("MM/dd/yyyy"));
            pdfTab.AddCell(data.Balance.ToString("C"));

            doc.Open();
            doc.Add(p);
            doc.Add(pdfTab);
            doc.Close();

            FileInfo info = new FileInfo(filePath);
            if (!info.Exists)
            {
                using (StreamWriter writer = info.CreateText())
                {
                    writer.WriteLine("Hello, I am a new text file");

                }
            }

            return File(info.OpenRead(), "application/pdf");
            /*}
            catch (Exception)
            {

                throw;
            }
            finally
            {
                doc.Close();
            }*/
        }
 public HairdressersController(BookingDBContext context)
 {
     _context = context;
 }
 public DetailsController(BookingDBContext context, AuthoriseUser auth)
 {
     _context = context; // Database
     _auth    = auth;    // Authentication service
 }
 public UsersController(BookingDBContext context)
 {
     _context = context;
 }
示例#19
0
        private readonly HotelDBContext HotelDB;     // The database of hotels

        public BookingAPIController(HotelDBContext hdb, BookingDBContext bdb)
        {
            BookingDB = bdb;
            HotelDB   = hdb;
        }
 public UserManagementController(BookingDBContext context, AuthoriseUser auth)
 {
     _context = context; // Database context
     _auth    = auth;    // Authentication service
 }
示例#21
0
 public BookingValidator(BookingDBContext context)
 {
     _context = context;
 }
示例#22
0
 public LoginController(BookingDBContext context)
 {
     _context = context;
 }
示例#23
0
 public AdminController(AuthoriseUser auth, BookingDBContext context)
 {
     _auth    = auth;    // Authorisation service
     _context = context; // Database
 }
示例#24
0
 public LoginController(BookingDBContext context)
 {
     _context = context; // The database context class
 }
 public BookingRepository(BookingDBContext bookingDBContext)
 {
     _bookingDBContext = bookingDBContext;
 }
 public TreatmentsController(BookingDBContext context)
 {
     _context = context;
 }