public void CreateTest()
        {
            //Arrange
            var seedDB = new List <CustomerModelDAL>();
            var seed   = new CustomerModelDAL
            {
                Email     = "*****@*****.**",
                Password  = PasswordHelperTool.PasswordSHA256Hasher("password"),
                FirstName = "First",
                LastName  = "Last"
            };

            seedDB.Add(seed);
            var controller = new CustomerUsersLogic(new CustomerDALStub(seedDB));
            var rightInput = new CustomerModelBLL {
                Email     = "*****@*****.**",
                Password  = "******",
                FirstName = "First",
                LastName  = "Last"
            };
            var wrongInput = new CustomerModelBLL {
                Email     = "",
                Password  = "",
                FirstName = "",
                LastName  = ""
            };

            //Act
            var result1 = controller.Create(rightInput);
            var result2 = controller.Create(wrongInput);

            //Assert
            Assert.IsTrue(result1 && !result2);
        }
Ejemplo n.º 2
0
        public ActionResult Register(WrapperUserObject userInput)
        {
            if (ModelState.IsValid)
            {
                var customer = _customerUsersLogic.Get(userInput.UserRegistrationObject.Email);
                if (customer == null)
                {
                    var customerModelBLL = new CustomerModelBLL()
                    {
                        Email     = userInput.UserRegistrationObject.Email,
                        Password  = userInput.UserRegistrationObject.Password,
                        FirstName = userInput.UserRegistrationObject.FirstName,
                        LastName  = userInput.UserRegistrationObject.LastName
                    };

                    var result = _customerUsersLogic.Create(customerModelBLL);

                    if (result)
                    {
                        Session["LoggedIn"] = true;
                        Session["Username"] = userInput.UserRegistrationObject.Email;
                    }
                }
                else
                {
                    var errorWrapper = new WrapperUserObject("Email already in use/Already existing user");
                    return(View("LogInModal", errorWrapper));
                }

                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("LogInModal"));
        }
Ejemplo n.º 3
0
        public ActionResult PostCustomer(CustomerViewModel customerViewModel)
        {
            if (Session["LoggedIn"] == null || Session["LoggedIn"].Equals(false))
            {
                return(RedirectToRoute(new
                {
                    controller = "Home",
                    action = "Index"
                }));
            }

            var customerModelBLL = new CustomerModelBLL()
            {
                FirstName = customerViewModel.FirstName,
                LastName  = customerViewModel.LastName,
                Email     = customerViewModel.Email,
                Password  = customerViewModel.Password,
            };

            var result = _customerUsersLogic.Create(customerModelBLL);

            if (result)
            {
                TempData["SuccessMessage"] = "Customer created successfully";
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["ErrorMessage"] = "Could not create customer";
                return(RedirectToAction("EditOrCreateCustomer"));
            }
        }