Beispiel #1
0
        public ActionResult Create([Bind(Include = "GenreID,GenreName")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
        public ActionResult Create([Bind(Include = "CustomerID,CustomerName,CustomerPhone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "RentalID,MovieID,CustomerID,RentalDate,DueDate,ReturnDate")] RentalRecord rentalRecord)
        {
            if (ModelState.IsValid)
            {
                db.RentalRecords.Add(rentalRecord);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "MovieName", rentalRecord.MovieID);
            return(View(rentalRecord));
        }
        public ActionResult Create([Bind(Include = "MovieID,MovieName,MovieDescription,MovieGenre")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MovieGenre = new SelectList(db.Genres, "GenreID", "GenreName", movie.MovieGenre);
            return(View(movie));
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            Employee selected = (Employee)EmployeeList.SelectedItem;

            if (selected != null)
            {
                using (var context = new MovieRentalEntities())
                {
                    if (MessageBox.Show("Are you sure you want to delete " + selected.FirstName + " " + selected.LastName + "?", "Delete Employee", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        // Remove all references to the movie
                        var employee = context.Employees.Where(emp => emp.SIN == selected.SIN).Single();
                        context.Employees.Remove(employee);

                        var orders = context.Orders.Where(o => o.SIN == selected.SIN);

                        foreach (Order order in orders)
                        {
                            order.SIN = null;
                        }

                        context.SaveChanges();
                        MessageBox.Show(selected.FirstName + " " + selected.LastName + " deleted");
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new MovieRentalEntities())
            {
                Customer customer = new Customer();
                {
                    customer.FirstName    = FirstNameBox.Text;
                    customer.LastName     = LastNameBox.Text;
                    customer.Address      = AddressBox.Text;
                    customer.City         = CityBox.Text;
                    customer.Province     = ProvinceBox.Text;
                    customer.PostalCode   = PostalCodeBox.Text;
                    customer.Phone        = PhoneNumberBox.Text;
                    customer.Email        = EmailBox.Text;
                    customer.CreditCard   = CreditCardBox.Text;
                    customer.Username     = UsernameBox.Text;
                    customer.Password     = PasswordBox.Password;
                    customer.Rating       = 0;
                    customer.CreationDate = DateTime.Today;

                    int value = int.Parse(AccountTypeBox.Text);
                    customer.AccountType     = value;
                    PasswordBox.PasswordChar = '•';
                }

                context.Customers.Add(customer);
                context.SaveChanges();
                MessageBox.Show("Customer added");
            }
        }
        private void Approve_Click(object sender, RoutedEventArgs e)
        {
            Order current = (Order)OrderList.SelectedItem;

            using (var context = new MovieRentalEntities())
            {
                var order = context.Orders.Include("Movie").SingleOrDefault(o => o.OrderID == current.OrderID);

                if (order != null)
                {
                    order.SIN            = employee.SIN;
                    order.RentalDate     = System.DateTime.Today;
                    order.ExpectedReturn = System.DateTime.Today.AddMonths(1);
                    order.Movie.NumberOfCopies--;
                    context.SaveChanges();

                    MessageBox.Show("Order has been approved");

                    // Refresh order list
                    OrderList.ItemsSource = null;
                    OrderList.ItemsSource = GetOrders();
                    OrderInfo.ItemsSource = null;
                }
            }
        }
        // TODO: Tab indices
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new MovieRentalEntities())
            {
                var customer = context.Customers.SingleOrDefault(c => c.AccountNumber == this.customer.AccountNumber);

                if (customer != null)
                {
                    if (!string.IsNullOrWhiteSpace(FirstNameBox.Text))
                    {
                        customer.FirstName = FirstNameBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(LastNameBox.Text))
                    {
                        customer.LastName = LastNameBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(AddressBox.Text))
                    {
                        customer.Address = AddressBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(CityBox.Text))
                    {
                        customer.City = CityBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(ProvinceBox.Text))
                    {
                        customer.Province = ProvinceBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PostalCodeBox.Text))
                    {
                        customer.PostalCode = PostalCodeBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PhoneNumberBox.Text))
                    {
                        customer.Phone = PhoneNumberBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(EmailBox.Text))
                    {
                        customer.Email = EmailBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(UsernameBox.Text))
                    {
                        customer.Username = UsernameBox.Text;
                    }

                    if (!string.IsNullOrWhiteSpace(PasswordBox.Password) && PasswordBox.Password == ConfirmBox.Password)
                    {
                        customer.Password = PasswordBox.Password;
                    }

                    context.SaveChanges();
                    MessageBox.Show("Changes saved");
                }
            }
        }
        private void ReturnButton_Click(object sender, RoutedEventArgs e)
        {
            OrderView current = (OrderView)OrderList.SelectedItem;

            using (var context = new MovieRentalEntities())
            {
                var order = context.Orders.Include("Movie").SingleOrDefault(o => o.OrderID == current.OrderID);

                order.ActualReturn = DateTime.Today;
                order.Movie.NumberOfCopies++;
                context.SaveChanges();
                MessageBox.Show("Movie has been returned");
            }
        }
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new MovieRentalEntities())
            {
                if (PasswordBox.Password == ConfirmBox.Password)
                {
                    try
                    {
                        string position = AccountType.SelectedItem.ToString();
                        int    type;

                        if (position == "Employee")
                        {
                            type = 1;
                        }
                        else
                        {
                            type = 0;
                        }
                        Employee employee = new Employee()
                        {
                            SIN         = SINBox.Text,
                            FirstName   = FirstNameBox.Text,
                            LastName    = LastNameBox.Text,
                            Address     = AddressBox.Text,
                            City        = CityBox.Text,
                            Province    = ProvinceBox.Text,
                            PostalCode  = PostalCodeBox.Text,
                            Phone       = PhoneBox.Text,
                            StartDate   = DateTime.Today,
                            Wage        = Convert.ToDecimal(WageBox.Text),
                            Username    = UsernameBox.Text,
                            Password    = PasswordBox.Password,
                            AccountType = type
                        };

                        context.Employees.Add(employee);
                        context.SaveChanges();

                        MessageBox.Show("Employee added");
                    }
                    catch
                    {
                        MessageBox.Show("Error adding employee");
                        return;
                    }
                }
            }
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            Movie current = (Movie)MovieList.SelectedItem;

            if (current != null)
            {
                using (var context = new MovieRentalEntities())
                {
                    if (MessageBox.Show("Are you sure you want to delete " + current.Title + "?", "Delete Movie", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        // Remove all references to the movie
                        var movie = context.Movies.Where(m => m.MovieID == current.MovieID).Single();
                        context.Movies.Remove(movie);

                        var orders = context.Orders.Where(o => o.MovieID == current.MovieID);

                        foreach (Order order in orders)
                        {
                            context.Orders.Remove(order);
                        }

                        var queues = context.Queues.Where(q => q.MovieID == current.MovieID);

                        foreach (Queue queue in queues)
                        {
                            context.Queues.Remove(queue);
                        }

                        var credits = context.Credits.Where(c => c.MovieID == current.MovieID);

                        foreach (Credit credit in credits)
                        {
                            context.Credits.Remove(credit);
                        }

                        context.SaveChanges();
                        MessageBox.Show(current.Title + " deleted");
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Beispiel #12
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            int copies; decimal fee;

            string genre = Genre.SelectedValue.ToString();

            try
            {
                copies = Convert.ToInt32(NumberOfCopies.Text);
            }
            catch
            {
                MessageBox.Show("Error in number of copies");
                return;
            }

            try
            {
                fee = Convert.ToDecimal(DistributionFee.Text);
            }
            catch
            {
                MessageBox.Show("Error in distribution fee");
                return;
            }

            using (var context = new MovieRentalEntities())
            {
                var movie = context.Movies.Where(m => m.MovieID == this.movie.MovieID).Single();

                movie.Genre           = genre;
                movie.NumberOfCopies  = copies;
                movie.DistributionFee = fee;

                context.SaveChanges();

                if (MessageBox.Show("Changes saved", movie.Title, MessageBoxButton.OK, MessageBoxImage.None) == MessageBoxResult.OK)
                {
                    this.Close();
                }
            }
        }
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new MovieRentalEntities())
            {
                var mov = context.Movies.Where(m => m.MovieID == this.movie.MovieID).Single();

                int total = (int)client.GetMovieAsync(mov.MovieID).Result.VoteAverage *client.GetMovieAsync(mov.MovieID).Result.VoteCount;
                int votes = client.GetMovieAsync(mov.MovieID).Result.VoteCount;

                votes = votes++;

                if (RateOne.IsChecked == true)
                {
                    total = total + 1;
                }
                else if (RateTwo.IsChecked == true)
                {
                    total = total + 2;
                }
                else if (RateThree.IsChecked == true)
                {
                    total = total + 3;
                }
                else if (RateFour.IsChecked == true)
                {
                    total = total + 4;
                }
                else if (RateFive.IsChecked == true)
                {
                    total = total + 5;
                }

                Console.WriteLine(total); Console.WriteLine(votes);

                mov.Rating = (int)Math.Round((float)(total / votes)) / 2;

                context.SaveChanges();

                this.Close();
            }
        }
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            Customer selected = (Customer)CustomerList.SelectedItem;

            if (selected != null)
            {
                using (var context = new MovieRentalEntities())
                {
                    if (MessageBox.Show("Are you sure you want to delete " + selected.FirstName + " " + selected.LastName + "?", "Delete Customer", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        var customer = context.Customers.Where(cus => cus.AccountNumber == selected.AccountNumber).Single();
                        context.Customers.Remove(customer);

                        context.SaveChanges();
                        MessageBox.Show(selected.FirstName + " " + selected.LastName + " deleted");
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            Customer selected = (Customer)CustomerList.SelectedItem;

            using (var context = new MovieRentalEntities())
            {
                var customer = context.Customers.Where(cus => cus.AccountNumber == selected.AccountNumber).Single();

                if (customer != null)
                {
                    if (!string.IsNullOrWhiteSpace(EmailBoxEdit.Text))
                    {
                        customer.Email = EmailBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(FirstNameBoxEdit.Text))
                    {
                        customer.FirstName = FirstNameBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(LastNameBoxEdit.Text))
                    {
                        customer.LastName = LastNameBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(AddressBoxEdit.Text))
                    {
                        customer.Address = AddressBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(CityBoxEdit.Text))
                    {
                        customer.City = CityBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(ProvinceBoxEdit.Text))
                    {
                        customer.Province = ProvinceBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PostalCodeBoxEdit.Text))
                    {
                        customer.PostalCode = PostalCodeBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PhoneNumberBoxEdit.Text))
                    {
                        customer.Phone = PhoneNumberBoxEdit.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(AccountTypeBoxEdit.Text))
                    {
                        int value = int.Parse(AccountTypeBoxEdit.Text);
                        customer.AccountType = value;
                    }
                    if (!string.IsNullOrWhiteSpace(UsernameBox.Text))
                    {
                        customer.Username = UsernameBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PasswordBox.Password))
                    {
                        customer.Password = PasswordBox.Password;
                    }

                    context.SaveChanges();
                    MessageBox.Show("Changes saved");
                }
            }
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            Employee selected = (Employee)EmployeeList.SelectedItem;

            using (var context = new MovieRentalEntities())
            {
                var employee = context.Employees.Where(emp => emp.SIN == selected.SIN).Single();

                if (employee != null)
                {
                    if (!string.IsNullOrWhiteSpace(SINBox.Text))
                    {
                        employee.SIN = SINBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(FirstNameBox.Text))
                    {
                        employee.FirstName = FirstNameBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(LastNameBox.Text))
                    {
                        employee.LastName = LastNameBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(AddressBox.Text))
                    {
                        employee.Address = AddressBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(CityBox.Text))
                    {
                        employee.City = CityBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(ProvinceBox.Text))
                    {
                        employee.Province = ProvinceBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PostalCodeBox.Text))
                    {
                        employee.PostalCode = PostalCodeBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(PhoneBox.Text))
                    {
                        employee.Phone = PhoneBox.Text;
                    }
                    if (!string.IsNullOrWhiteSpace(WageBox.Text))
                    {
                        employee.Wage = Convert.ToDecimal(WageBox.Text);
                    }
                    if (!string.IsNullOrWhiteSpace(UsernameBox.Text))
                    {
                        employee.Username = UsernameBox.Text;
                    }

                    if (!string.IsNullOrWhiteSpace(PasswordBox.Password) && PasswordBox.Password == ConfirmBox.Password)
                    {
                        employee.Password = PasswordBox.Password;
                    }

                    if (AccountType.SelectedIndex != -1)
                    {
                        string position = AccountType.SelectedItem.ToString();

                        if (position == "Employee")
                        {
                            employee.AccountType = 1;
                        }
                        else
                        {
                            employee.AccountType = 0;
                        }
                    }

                    context.SaveChanges();
                    MessageBox.Show("Changes saved");
                }
            }

            Add.Visibility = Visibility.Visible;
        }
        private void Select_Click(object sender, RoutedEventArgs e)
        {
            int newAccount;

            currentPage = UpgradeFrame.Content.GetType().Name.ToString();

            if (currentPage == "Limited")
            {
                if (MessageBox.Show("Are you sure you want to change to the Limited account?", "Account request", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    newAccount = 0;
                }
                else
                {
                    return;
                }
            }
            // Current page is Unlimited 1, go to Unlimited 2
            else if (currentPage == "Unlimited1")
            {
                if (MessageBox.Show("Are you sure you want to change to the Unlimited1 account?", "Account request", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    newAccount = 1;
                }
                else
                {
                    return;
                }
            }
            // Current page is Unlimited 2, go to Unlimited 3 and hide Next button
            else if (currentPage == "Unlimited2")
            {
                if (MessageBox.Show("Are you sure you want to change to the Unlimited2 account?", "Account request", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    newAccount = 2;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (MessageBox.Show("Are you sure you want to change to the Unlimited3 account?", "Account request", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    newAccount = 3;
                }
                else
                {
                    return;
                }
            }

            using (var context = new MovieRentalEntities())
            {
                var customer = context.Customers.SingleOrDefault(c => c.AccountNumber == this.customer.AccountNumber);

                customer.AccountType = newAccount;
                context.SaveChanges();
            }
        }