public ActionResult CreateForm()
        {
            HomeDepotContext _context  = new HomeDepotContext();
            var createBookingViewModel = new CreateBookingViewModel();

            return(View(createBookingViewModel));
        }
Exemple #2
0
 public MainPage()
 {
     InitializeComponent();
     _context     = new HomeDepotContext();
     allCostumers = _context.Customers.ToList <Customer>();
     FilterCostumers();
 }
Exemple #3
0
        public ActionResult Login(Customer customer)
        {
            if (ModelState.IsValid)
            {
                using (HomeDepotContext context = new HomeDepotContext())
                {
                    //probably doesnt work

                    var cust = context.Customers.ToList().Find(c => c.Email.Equals(customer.Email) && c.Password.Equals(customer.Password));
                    if (cust != null)
                    {
                        CustomerPageViewModel customerPage = new CustomerPageViewModel();
                        customerPage.Customer   = cust;
                        customerPage.Bookings   = context.Bookings.ToList().FindAll(b => b.CustomerId == cust.CustomerId);
                        customerPage.Tools      = context.Tools.ToList();
                        Session["customerPage"] = customerPage;
                        return(View("CustomerPage", customerPage));
                    }
                    else
                    {
                        ViewBag.Error = "Invalid login info";
                    }
                }
            }
            return(View("Login"));
        }
Exemple #4
0
        public CreateBookingViewModel()
        {
            Tools = new List <Tool>();
            HomeDepotContext _context = new HomeDepotContext();

            _context.Tools.ToList().ForEach(t => Tools.Add(t));
        }
        public NewC()
        {
            _context = new HomeDepotContext();
            List <Tool>     tools     = _context.Tools.ToList <Tool>();
            List <Customer> costumers = _context.Customers.ToList <Customer>();

            InitializeComponent();
        }
Exemple #6
0
        public MainWindow()
        {
            InitializeComponent();
            Main.Content = new MainPage();
            _context     = new HomeDepotContext();
            List <Customer> costumers = _context.Customers.ToList <Customer>();

            this.DataContext = costumers;
        }
        public MainWindow()
        {
            InitializeComponent();

            _context = new HomeDepotContext();


            //Eager loading
            ListCustomers.DataContext = _context.customers.Include(c => c.Bookings).ToList();
        }
Exemple #8
0
 public RentOverview(Rent rent)
 {
     _context = new HomeDepotContext();
     InitializeComponent();
     currentRent        = rent;
     id.Text            = rent.Id.ToString();
     tool.Text          = rent.RentTool.Name;
     pickup.Text        = rent.PickUp;
     days.Text          = rent.Days.ToString();
     combo.ItemsSource  = Enum.GetValues(typeof(Status));
     combo.SelectedItem = rent.Status;
 }
Exemple #9
0
        public CostumerPage(Customer costumer)
        {
            _context = new HomeDepotContext();
            InitializeComponent();

            navn.Text       = costumer.Name;
            email.Text      = costumer.Email;
            brugerid.Text   = costumer.CustomerId.ToString();
            brugernavn.Text = costumer.Username;
            password.Text   = costumer.Password;
            List <Rent> bookinger = _context.Rents.Where(r => r.Customer.CustomerId.Equals(costumer.CustomerId)).ToList();

            this.DataContext = bookinger;
        }
Exemple #10
0
        public ActionResult CreateBooking()
        {
            List <SelectListItem> toolNames = new List <SelectListItem>();

            using (HomeDepotContext context = new HomeDepotContext())
            {
                foreach (var tool in context.Tools.ToList())
                {
                    toolNames.Add(new SelectListItem {
                        Text = tool.Name
                    });
                }
            }
            toolNames.OrderBy(t => t.Text);
            Session["toolNames"] = toolNames;
            return(View());
        }
Exemple #11
0
        public ActionResult CustomerPage(CustomerPageViewModel customerPage)
        {
            if (Session["customerPage"] != null)
            {
                CustomerPageViewModel sCustomerPage = Session["customerPage"] as CustomerPageViewModel;
                using (HomeDepotContext context = new HomeDepotContext())
                {
                    sCustomerPage.Bookings = context.Bookings.ToList().FindAll(b => b.CustomerId == sCustomerPage.Customer.CustomerId);
                }

                return(View(Session["customerPage"] as CustomerPageViewModel));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Exemple #12
0
        public ActionResult CreateBooking(Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateBooking"));
            }

            using (HomeDepotContext context = new HomeDepotContext())
            {
                //skal gemme en booking i db og redirecte til customerpage (eventuelt besked med at booking er oprettet + fejl beskeder for variabler)

                string         selectedTool = Request.Form["ToolNames"].ToString();
                Tool           tool         = context.Tools.ToList().Find(t => t.Name.Equals(selectedTool));
                List <Booking> toolBookings = context.Bookings.ToList().FindAll(b => b.ToolId == tool.ToolId);
                foreach (var b in toolBookings)
                {
                    for (int i = 0; i < b.Days; i++)
                    {
                        if (b.PickupDay.AddDays(i) == booking.PickupDay && b.PickupDay == booking.PickupDay.AddDays(i))
                        {
                            ViewBag.Error = "Tool already booked for this period \n Available after: " + b.PickupDay.ToString("dd/MM/yyy/");
                            return(View());
                        }
                    }
                }
                if (Session["customerPage"] == null)
                {
                    return(View("Login"));
                }
                else
                {
                    CustomerPageViewModel customerPage = Session["customerPage"] as CustomerPageViewModel;
                    context.Bookings.Add(new Booking {
                        PickupDay = booking.PickupDay, CustomerId = customerPage.Customer.CustomerId, Status = "Reserveret", Days = booking.Days, ToolId = tool.ToolId
                    });
                    context.SaveChanges();
                }
            }
            return(RedirectToAction("Customerpage", Session["customerPage"]));
            //return View("CustomerPage", Session["customerPage"]);
        }
        public ActionResult ViewBooking()
        {
            HomeDepotContext _context = new HomeDepotContext();
            Customer         customer = Session["user"] as Customer;
            List <Booking>   bookings = new List <Booking>();

            if (customer != null)
            {
                _context.Bookings.ToList().ForEach((e) => {
                    if (e.CustomerID == customer.Id)
                    {
                        bookings.Add(e);
                    }
                });
                var bookingsViewlModel = new BookingsViewModel();
                bookingsViewlModel.bookings = bookings;
                return(View(bookingsViewlModel));
            }
            else
            {
                return(Redirect("/login/login"));
            }
        }
        public ActionResult Create(CreateBookingViewModel createBookingViewModel)
        {
            HomeDepotContext _context = new HomeDepotContext();
            Customer         customer = Session["user"] as Customer;

            if (customer != null)
            {
                Tool    tool    = _context.Tools.Find(createBookingViewModel.SelectedValue);
                Booking booking = new Booking();
                booking.Status     = "Booked";
                booking.PickUpDate = createBookingViewModel.PickUpDate;
                booking.Days       = createBookingViewModel.Days;
                booking.ToolID     = tool.Id;
                booking.CustomerID = customer.Id;
                _context.Bookings.Add(booking);
                _context.SaveChanges();
                return(Redirect("/booking/viewbooking"));
            }
            else
            {
                return(Redirect("/login/login"));
            }
        }
Exemple #15
0
        public ActionResult Autherize(string usernameData, string passwordData)
        {
            _context = new HomeDepotContext();
            Customer user = null;

            _context.Customers.ToList().ForEach(c =>
            {
                if (c.Username == usernameData && c.Password == passwordData)
                {
                    user = c;
                }
            }
                                                );
            if (user == null)
            {
                return(Redirect("/login/login"));
            }
            else
            {
                Session["user"] = user;
                return(View("Home"));
            }
        }
Exemple #16
0
 public MainWindow()
 {
     InitializeComponent();
     _context = new HomeDepotContext();
     CustomerListBox.ItemsSource = _context.Customers.ToList();
 }
Exemple #17
0
 public CreateCustomerPage()
 {
     InitializeComponent();
     _context = new HomeDepotContext();
 }
 public CustomerPage()
 {
     InitializeComponent();
     _context = new HomeDepotContext();
     loadCustomers();
 }