public void GetStoreLocationsReturnsAllStoreLocationsInAList()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                List <StoreLocation> storeLocations = new List <StoreLocation>();
                //int loginChoice = 3;
                StoreLocation o = new StoreLocation("Jupiter");
                storeLocations.Add(o);

                Assert.Equal(true, storeLocations.Count == 1);
                Assert.Equal(true, o.location == "Jupiter");
            }
        }
        public ActionResult Index(UserLoginModel userLoginModel, string ReturnUrl = "")
        {
            string message = "";


            using (GwDbContext context = new GwDbContext())
            {
                var v = context.Users.Where(a => a.Email == userLoginModel.Email).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(Crypto.Hash(userLoginModel.Password), v.Password) == 0)
                    {
                        int timeOut = userLoginModel.RememberMe ? 525600 : 1;
                        var ticket  =
                            new FormsAuthenticationTicket(userLoginModel.Email, userLoginModel.RememberMe, timeOut);
                        string enctypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, enctypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeOut);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);


                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            #region MINE

                            if (v.Type == "Admin")
                            {
                                return(RedirectToActionPermanent("Index", "Admin"));
                            }


                            #endregion

                            else
                            {
                                return(RedirectToActionPermanent("AfterLogin", "Home"));
                            }
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }


            ViewBag.Message = message;
            return(View());
        }
 public bool IsEmailExist(string email)
 {
     using (GwDbContext context = new GwDbContext())
     {
         var v = context.Users.Where(a => a.Email == email).FirstOrDefault();
         return(v != null);
     }
 }
Exemple #4
0
 public bool IsProductExist(string product)
 {
     using (GwDbContext context = new GwDbContext())
     {
         var v = context.Products.Where(a => a.ProductName == product).FirstOrDefault();
         return(v != null);
     }
 }
        public ActionResult Registration(User user)
        {
            bool   Status  = false;
            string message = "";

            user.Type = "Customer";

            //Model Validation
            if (ModelState.IsValid)
            {
                //Email is already Exists
                var isExist = IsEmailExist(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExists", "Email already exists");
                    ViewBag.Message = message;
                    ViewBag.Status  = Status;
                    return(View(user));
                }



                #region Password Hashing

                user.Password       = Crypto.Hash(user.Password);
                user.RepeatPassword = Crypto.Hash(user.RepeatPassword);

                #endregion



                #region Save to Database

                using (GwDbContext context = new GwDbContext())
                {
                    context.Users.Add(user);
                    context.SaveChanges();

                    //send email to user
                    //SendVerificationEmail(user.Email);
                    //message = "Registration Successful"+"An email has been to your Email:"+user.Email;
                    message = "Registered successfully";
                    Status  = true;
                }

                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            TempData["Message"] = message;
            ViewBag.Message     = message;
            ViewBag.Status      = Status;
            //return RedirectToAction("Index", "Home");
            return(View());
        }
        public void GetProductByNameShouldReturnTheObjectWithTheNamePassedIntoTheMethod()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                Product product = rs.GetProductByName("Guitar");
                Assert.Equal(true, product.productDescription == "Fender");
            }
        }
        public void IsAdminTakesInTwoStringsAndComparesThemToAdmin()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Functions fs = new Functions();


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                string f = "Admin";
                string l = "Admin";
                Assert.Equal(true, fs.IsAdmin(f, l));
            }
        }
        public void GetLoginChoiceReturnsTheIntOfTheCurrentLoginChoice()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Functions fs = new Functions();


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                //int loginChoice = 3;
                int choice = fs.GetLoginChoice();

                Assert.Equal(true, fs.GetLoginChoice() == 0);
            }
        }
        public void MuliptyItself()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            int z;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);

                int x = 5;
                z = x * x;

                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                Assert.Equal(25, z);
            }
        }
        public void GetAllInventory()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                List <Inventory> allInventory = rs.GetAllInventory();


                Assert.Equal(true, allInventory.Count == 12);
                //Assert.Equal(true, o.location == "Jupiter");
            }
        }
        public void AddToOrderHistory()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                List <Order> orderHistory = new List <Order>();
                //int loginChoice = 3;
                Order o = new Order();
                orderHistory.Add(o);

                Assert.Equal(true, orderHistory.Count == 1);
            }
        }
        public void AddPurchasedProduct()
        {
            var options = new DbContextOptionsBuilder <GwDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            using (var context = new GwDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                Repository rs = new Repository(context);


                context.SaveChanges();
            }

            using (var context = new GwDbContext(options))
            {
                List <PurchasedProducts> purchasedProducts = new List <PurchasedProducts>();
                //int loginChoice = 3;
                PurchasedProducts o = new PurchasedProducts();
                purchasedProducts.Add(o);

                Assert.Equal(true, purchasedProducts.Count == 1);
            }
        }