public IActionResult CreateProject(CreateProjectViewModel vm)
        {
            if (!_auth.Authorise(RolesEnum.Admin, _context)) // Check logged in
            {
                return(Redirect("~/Project/Dashboard"));
            }

            // Create a new project and fill in fields
            var newProj = new Projects();

            newProj.BookingNumber      = vm.ProjectNumber;
            newProj.MaximumMinutes     = vm.MaxHours * 60;
            newProj.CurrentUsedMinutes = 0;
            newProj.Locked             = false;
            newProj.ProjectDescription = vm.ProjectDesc;
            newProj.ProjectName        = vm.ProjectName;

            // Add project to database
            _context.Projects.Add(newProj);
            // Save database
            _context.SaveChanges();

            // Kick out to user management
            return(Redirect("~/UserManagement/ManageUsers"));
        }
Example #2
0
        // Function to accept a request
        public IActionResult AcceptReq(int id)
        {
            if (!_auth.Authorise(RolesEnum.Admin, _context)) // Authenticate the user
            {
                return(Redirect("~/Project/Dashboard"));
            }

            // Check the request Id exists
            if (!_context.AdminRequests.Any(r => r.RequestId == id))
            {
                return(RedirectToAction("MailBox"));
            }

            // Get the record and update values
            var rec = _context.AdminRequests.First(r => r.RequestId == id);

            rec.Responded         = true;
            rec.RespondedByUserId = _context.Users.First(u => u.UserName == HttpContext.Session.GetString("Username")).UserId;
            rec.DateResponded     = DateTime.Now;
            rec.Response          = true;

            // Save to the database
            _context.SaveChanges();

            // Redirect back to the mailbox
            return(RedirectToAction("Mailbox"));
        }
Example #3
0
        // Delete project action
        public IActionResult DeleteProject(int id)
        {
            if (!_auth.Authorise(RolesEnum.Admin, _context)) // Authenticate the user
            {
                return(Redirect("~/Project/Dashboard"));
            }

            if (!_context.Projects.Any(p => p.ProjectId == id)) // Make sure the project exists
            {
                return(RedirectToAction("ManageProjects"));
            }

            var projectToRemove = _context.Projects.First(p => p.ProjectId == id);                             // Get the record

            _context.Projects.Remove(projectToRemove);                                                         // Remove the project

            var projectUsersToRemove   = _context.ProjectUsers.Where(p => p.ProjectId == id).ToList();         // Get the projectUsers to remove
            var projectMinutesToRemove = _context.ProjectMinutesBooked.Where(p => p.ProjectId == id).ToList(); // Get the minutes to remove

            _context.ProjectUsers.RemoveRange(projectUsersToRemove);                                           // Remove the projectusers
            _context.ProjectMinutesBooked.RemoveRange(projectMinutesToRemove);                                 // remove the minutes

            _context.SaveChanges();                                                                            // Save the database

            // Redirect back to manage projects
            return(RedirectToAction("ManageProjects"));
        }
        // Action to delete a broadcast, gets the id from the url
        public IActionResult DeleteBroadcast(int id)
        {
            if (!_auth.Authorise(RolesEnum.Admin, _context)) // Authenticate the user
            {
                Redirect("~/Project/Dashboard");
            }

            _context.Broadcasts.Remove(_context.Broadcasts.First(i => i.BroadcastId == id)); // Remove the broadcast with the correct id

            _context.SaveChanges();                                                          // Save the changes to the database

            // Redirect back to the list view
            return(RedirectToAction("List"));
        }
Example #5
0
        public IActionResult Create(UserViewModel model)
        {
            var salt           = BCrypt.BCryptHelper.GenerateSalt();
            var password       = RandomString(6);
            var hashedPassword = BCrypt.BCryptHelper.HashPassword(password, salt);

            User user = new User()
            {
                Email       = model.Email,
                Password    = hashedPassword,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Address     = model.Address,
                BirthDate   = model.BirthDate,
                PhoneNumber = model.PhoneNumber,
                Role        = Infrastructure.Domain.Models.Enums.Role.Customer,
                Sex         = model.Sex,
                UserID      = Guid.NewGuid()
            };

            var fullname = model.FirstName + model.LastName;

            _context.Users.Add(user);
            _context.SaveChanges();

            this.SendNow("Hello " + fullname + " Please use this one time password to login:"******"Peninsula Account Registration", "Welcome to Peninsula!");

            return(Redirect("../"));
        }
        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();
        }
Example #7
0
        public IActionResult NewBook(BookViewModel model)
        {


            Guid rID = Guid.NewGuid();
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Error", "Required");
                return View(model);
            }
            Reservation reservation = new Reservation()
            { 
                FacilityID = model.FacilityID,
                ReservationID = rID,
                UserID = User.GetId(),
                FacilityType = model.FacilityType,
                CheckIn = model.CheckIn,
                CheckOut = model.CheckOut
            };
            Billing billing = new Billing()
            {
              UserID = User.GetId(),
              BillingID = Guid.NewGuid(),
              ReservationID = rID,
              TotalAmount = model.RentCharges,
              MiscCharges = 0,
              RentCharges = model.RentCharges,
            };
            _context.Reservations.Add(reservation);
            _context.Billings.Add(billing);
            _context.SaveChanges();
            this.SendNow("Hello " + this.User.GetFullName() + "Thank you for Booking in Peninsula Hotel and Resort" +  "Check In:" + model.CheckIn  + "Check Out:" + model.CheckOut + "Payment:" + model.RentCharges, this.User.GetEmailAddress(), "Peninsula Confirmed Reservation", "Thank you for making a Reservation in Peninsula!");
            return Redirect("~/");
        }
        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();
            }
        }
        public IActionResult CreateRequest(CreateRequestViewModel vm)
        {
            // Check it's valid
            if (vm.SelectedType == "Choose Request Type" || string.IsNullOrEmpty(vm.Reason))
            {
                return(RedirectToAction("CreateRequest"));
            }

            // Create a new admin request
            var newReq = new AdminRequests();

            newReq.RequestDescription = vm.Reason;
            newReq.SentByUserId       = _context.Users.First(u => u.UserName == HttpContext.Session.GetString("Username")).UserId;
            newReq.Responded          = false;
            newReq.DateRequested      = DateTime.Now;
            newReq.RequestTypeId      = _context.RequestTypes.First(r => r.RequestName == vm.SelectedType).RequestTypeId;

            // Add it to database
            _context.AdminRequests.Add(newReq);

            // Save database
            _context.SaveChanges();

            // Redirect to dashboard
            return(Redirect("~/Project/Dashboard"));
        }
Example #10
0
        public ActionResult Create([Bind(Include = "ID,RoomNumber,FromDate,ToDate,userId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                booking.userId = User.Identity.GetUserId();
                db.Bookings.Add(booking);
                db.SaveChanges();

                // Audit booking submitted
                Audit audit = new Audit();
                audit.Date   = DateTime.Now;
                audit.UserId = User.Identity.GetUserId();
                audit.Event  = "User booking submitted: " + User.Identity.GetUserName() + " (Room:" + booking.RoomNumber + ")";
                var audit_result = new AuditsController().Create(audit);

                return(RedirectToAction("Details/" + booking.ID));
            }

            return(View(booking));
        }
Example #11
0
        public static Operation Add(Customer customer)
        {
            try
            {
                db.Customers.Add(customer);
                db.SaveChanges();

                return(new Operation()
                {
                    Code = "200",
                    Message = "Ok",
                    ReferenceId = customer.Id
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "500",
                    Message = e.Message
                });
            }
        }
Example #12
0
        public ActionResult Create(Booking booking)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(booking);
                db.SaveChanges();
                List <Booking> bookingList = db.Bookings.ToList();

                foreach (var x in bookingList)
                {
                    if ((x.ClientId == booking.ClientId) &&
                        (x.CheckIn.CompareTo(booking.CheckIn) == 0) &&
                        (x.CheckOut.CompareTo(booking.CheckOut) == 0)
                        )
                    {
                        booking = x;
                    }
                }

                return(RedirectToAction("ChooseRooms", "Room", new { bookingId = booking.BookingId }));
            }

            return(View(booking));
        }
Example #13
0
        public static Operation Add(Room room)
        {
            try
            {
                db.Rooms.Add(room);
                db.SaveChanges();

                return(new Operation()
                {
                    Code = "200",
                    Message = "Ok",
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "500",
                    Message = e.Message
                });
            }
        }
Example #14
0
        public static Operation Add(Reservation reservation)
        {
            try
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();

                return(new Operation()
                {
                    Code = "200",
                    Message = "Ok",
                    ReferenceId = reservation.ReservationID
                });
            }
            catch (Exception e)
            {
                return(new Operation()
                {
                    Code = "500",
                    Message = e.Message
                });
            }
        }
 public void Save()
 {
     context.SaveChanges();
 }
        public IActionResult AddUser(AddUserViewModel vm)
        {
            if (!_auth.Authorise(RolesEnum.Admin, _context)) // Check logged in as admin
            {
                return(Redirect("~/Project/Dashboard"));
            }

            // Reset error message
            vm.ErrorMessage = "";
            // Get roles from database and fill in field
            List <Roles> roles = _context.Roles.ToList();

            vm.AllRoles = roles;

            // Create new user
            var newUser = new Users();

            // If username exists
            var userTemp = _context.Users.Any(r => r.UserName == vm.UserName);

            if (userTemp)
            {
                vm.ErrorMessage += "Username already exists\n";
            }
            //Validate Password
            if (vm.Password != vm.ConfirmPassword)
            {
                vm.ErrorMessage += "Passwords must be equal.\n";
            }

            // If there's an error message
            if (vm.ErrorMessage != "")
            {
                return(View(vm));
            }


            // Encrypt Password
            // Generate Salt
            var salt = Salter.Shake();

            // Hash Password
            var hashedPass = Hasher.Hash(vm.Password + salt);

            // Fill in fields
            newUser.UserName       = vm.UserName;
            newUser.HashedPassword = hashedPass;
            newUser.Salt           = salt;

            newUser.RoleId = _context.Roles.First(r => r.RoleName == vm.RoleName).RoleId;

            // check if email is null

            if (vm.Email != null)
            {
                newUser.Email = vm.Email; // Only add email if one exists
            }

            // Add users to database
            _context.Users.Add(newUser);

            // Save the database
            _context.SaveChanges();

            // Redirect to the login page
            return(Redirect("/Login/Index"));
        }