public ActionResult Login(FormCollection collection)
        {
            var email = Request.Form["email"];
            var password = Request.Form["password"];

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                return View("LoginError");

            var context = new WebAppContext();
            var user = context.Users.Where(u => u.Email == email).FirstOrDefault();

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                return View("LoginError");

            var encryptedPassword = EncryptPassword(password);

            if (string.Compare(user.Password, encryptedPassword, true) == 0)
            {
                var dummySession = new DummySession() { UserID = user.ID.ToString() };

                TempData["DummySession"] = dummySession;

                if(user.IsAdmin)
                    return RedirectToAction("Index", "AdminCustomerList");

                return RedirectToAction("Index", "CustomerList");
            }

            return View("LoginError");
        }
Beispiel #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WebAppContext(
                       serviceProvider.GetRequiredService <DbContextOptions <WebAppContext> >()))
            {
                if (context.Car.Any())
                {
                    return;   // Cars has been seeded
                }

                context.Car.AddRange(
                    new Car
                {
                    Brand = "VW",
                    Model = "Golf V",
                    Year  = 2007,
                    Hk    = 120,
                    Price = 270000
                },
                    new Car
                {
                    Brand = "Audi",
                    Model = "A6",
                    Year  = 2013,
                    Hk    = 220,
                    Price = 360000
                },
                    new Car
                {
                    Brand = "Ford",
                    Model = "Focus",
                    Year  = 2016,
                    Hk    = 170,
                    Price = 170000
                },
                    new Car
                {
                    Brand = "Jaguar",
                    Model = "XE",
                    Year  = 2017,
                    Hk    = 360,
                    Price = 400000
                },
                    new Car
                {
                    Brand = "Toyota",
                    Model = "Prius",
                    Year  = 2015,
                    Hk    = 90,
                    Price = 105000
                }


                    );
                context.SaveChanges();
            }
        }
Beispiel #3
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WebAppContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <WebAppContext> >()))
            {
                // Look for any movies.
                if (context.Movies.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movies.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "King of Boys 2",
                    ReleaseDate = DateTime.Parse("2019-9-09"),
                    Genre       = "Tragy Comedy",
                    Price       = 7.92M
                },
                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }
 public FiltersViewModel(WebAppContext context)
 {
     //utilizando a consulta context.Users.Where(u => !u.IsAdmin) uma exception era disparada
     Sellers = context.Users.Where(u => u.ID.ToString() != User.ADMIN_ID);
     Cities = context.Cities;
     Classifications = context.Classifications;
     Genders = new List<Gender>()
     {
         new Gender() { ID = "M", Name = "M" },
         new Gender() { ID = "F", Name = "F" }
     };
 }
        public JsonResult GetRegions(string id)
        {
            var context = new WebAppContext();
            var filteredRegions = context.Regions.Where(r=>r.CityID.ToString() == id);

            var regions = new List<SelectListItem>();

            regions.Add(new SelectListItem() { Value = "", Text = "" });
            foreach (var region in filteredRegions)
                regions.Add(new SelectListItem() { Value = region.ID.ToString(), Text = region.Name });

            return Json(new SelectList(regions, "Value", "Text"));
        }
        public ActionResult ApplyFilters()
        {
            var dummySession = (DummySession)TempData["DummySession"];
            if (dummySession == null || dummySession.UserID == null)
                return RedirectToAction("Login", "Home");

            dummySession = UpdateFilters(dummySession);

            TempData["DummySession"] = dummySession;

            var context = new WebAppContext();
            var customers = context.GetCustomers();

            if (!string.IsNullOrEmpty(dummySession.FilterName))
                customers = customers.Where(c => c.Name.IndexOf(dummySession.FilterName) >= 0);

            if (!string.IsNullOrEmpty(dummySession.FilterCity))
                customers = customers.Where(c => c.Region.CityID.ToString() == dummySession.FilterCity);

            if (!string.IsNullOrEmpty(dummySession.FilterRegion))
                customers = customers.Where(c => c.Region.ID.ToString() == dummySession.FilterRegion);

            if (!string.IsNullOrEmpty(dummySession.FilterClassification))
                customers = customers.Where(c => c.ClassificationID.ToString() == dummySession.FilterClassification);

            if (!string.IsNullOrEmpty(dummySession.FilterSeller))
                customers = customers.Where(c => c.SellerID.ToString() == dummySession.FilterSeller);

            if (!string.IsNullOrEmpty(dummySession.FilterGender))
                customers = customers.Where(c => c.Gender == dummySession.FilterGender);

            if (dummySession.FilterDateMin > 0)
                customers = customers.Where(c => int.Parse(c.LastPurchase.ToString("yyyyMMdd")) >= dummySession.FilterDateMin);

            if (dummySession.FilterDateMax > 0)
                customers = customers.Where(c => int.Parse(c.LastPurchase.ToString("yyyyMMdd")) <= dummySession.FilterDateMax);

            TempData.Keep("DummySession");

            ViewBag.ViewModel = new FiltersViewModel(context);
            return AppliedFilters(customers);
        }
Beispiel #7
0
 public DeleteModel(WebApp.Models.WebAppContext context)
 {
     _context = context;
 }
Beispiel #8
0
 public EditModel(WebApp.Models.WebAppContext context)
 {
     _context = context;
 }
Beispiel #9
0
 public CreateModel(WebApp.Models.WebAppContext context)
 {
     _context = context;
 }
Beispiel #10
0
 public WebAppRepository(WebAppContext context)
 {
     _context = context;
 }
Beispiel #11
0
 public WebAppSeedData(WebAppContext context, UserManager <WebAppUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Beispiel #12
0
 public MoviesController(WebAppContext context)
 {
     _context = context;
 }
Beispiel #13
0
 public DetailsModel(WebApp.Models.WebAppContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public IndexModel(WebApp.Models.WebAppContext context)
 {
     _context = context;
 }