Esempio n. 1
0
        public async Task AddOwnerNotAdmin()
        {
            var context = new POAMDbContext();

            var ownerController = new OwnerController(context);


            RemoveUser(context);

            var user   = GenerateUser(context);
            var result = await ownerController.AddOwner(user);

            var existingOwner = context.Owner.FirstOrDefault(o => o.Username == user.Username);

            Assert.Null(existingOwner);
            var redirectResult = Assert.IsType <RedirectResult>(result);

            Assert.NotNull(redirectResult);
            Assert.Equal("~/Home/Index", redirectResult.Url);
        }
Esempio n. 2
0
        public async Task AddOwnerFailedUsernameExisting()
        {
            var context = new POAMDbContext();

            var ownerController = new OwnerController(context);

            RemoveAdmin(context);

            var user = CreateUser(context);

            Authentication.Instance.AdminLogin(CreateAdmin(context));

            var result = await ownerController.AddOwner(user);

            var redirectResult = Assert.IsType <ViewResult>(result);

            Assert.NotNull(redirectResult);
            Assert.True(string.IsNullOrEmpty(redirectResult.ViewName) || redirectResult.ViewName == "AddOwner");
            Authentication.Instance.Logout();
            RemoveAdmin(context);
        }
Esempio n. 3
0
        public async Task AddOwnerSuccessful()
        {
            var context = new POAMDbContext();

            var ownerController = new OwnerController(context);

            RemoveAdmin(context);
            RemoveUser(context);

            Authentication.Instance.AdminLogin(CreateAdmin(context));
            var user   = GenerateUser(context);
            var result = await ownerController.AddOwner(user);

            var existingOwner = context.Owner.FirstOrDefault(o => o.Username == user.Username);

            Assert.NotNull(existingOwner);
            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.NotNull(redirectResult);
            Assert.Equal("OwnersList", redirectResult.ActionName);

            Authentication.Instance.Logout();
            RemoveAdmin(context);
        }
Esempio n. 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (AllValidInputs() && IsValidEmail(txtEmail.Text) && ((panelNew.Visible == true && IsValidYear(txtYear.Text) && AllNewCarValidInputs()) || (panelExist.Visible == true && cmbSelect.SelectedItem != null)))
            {
                int vehicleID = 0;
                int ownerID   = 0;
                int status    = 1;

                //add new owner
                Owner newOwner = new Owner();

                string formattedPhoneNumber =
                    txtPhoneAreaCode.Text + "-" +
                    txtPhoneFirstThreeDigits.Text + "-" +
                    txtPhoneLastFourDigits.Text;

                newOwner.firstName     = txtFirstName.Text;
                newOwner.lastName      = txtLastName.Text;
                newOwner.streetAddress = txtStreet.Text;
                newOwner.city          = txtCity.Text;
                newOwner.state         = cmbState.Text;
                newOwner.zip           = txtZip.Text;
                newOwner.phoneNumber   = formattedPhoneNumber;
                newOwner.emailAddress  = txtEmail.Text;


                if (panelNew.Visible == true)
                {
                    //add new vehicle
                    Vehicle newVehicle = new Vehicle();
                    newVehicle.make  = txtMake.Text;
                    newVehicle.model = txtModel.Text;
                    newVehicle.VIN   = txtVIN.Text;
                    newVehicle.year  = txtYear.Text;
                    vehicleID        = vehControl.AddVehicle(newVehicle);
                }
                else
                {
                    vehicleID = int.Parse(cmbSelect.SelectedValue.ToString());
                }

                ownerID = ownControl.AddOwner(newOwner);

                //link vehicle to owner (add entry to OwnerVehicle table)
                OwnerVehicle newOwnerVehicle = new OwnerVehicle();
                newOwnerVehicle.ownerID   = ownerID;
                newOwnerVehicle.vehicleID = vehicleID;

                status = ownVehControl.AddOwnerVehicle(newOwnerVehicle);

                if (ownerID != 0 && vehicleID != 0 && status == 0)
                {
                    MessageBox.Show("You have successfully created a new customer!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There was an error while saving, please try again.");
                }
            }
        }