コード例 #1
0
        public ActionResult Index(int?brand, int?model)
        {
            JivivContext context = new JivivContext();
            var          models  = context.Models.Where(x => x.BrandId == brand).ToList();
            var          brands  = context.Brands.ToList();

            ViewBag.Brands = new SelectList(brands, "Id", "Name");
            ViewBag.Models = new SelectList(models, "Id", "Name");
            var detail    = new DetailSaleInformation();
            var lstBrands = new List <Brand>();
            var lstModels = new List <CarModel>();
            var lstUsers  = new List <User>();
            var sales     = context.Sales.Where(x => x.BrandId == brand && x.ModelId == model).ToList();

            foreach (var item in sales)
            {
                lstBrands.Add(context.Brands.Find(item.BrandId));
                lstModels.Add(context.Models.Find(item.ModelId));
                lstUsers.Add(context.Users.Find(item.UserId));
            }
            detail.Brands = lstBrands;
            detail.Models = lstModels;
            detail.Users  = lstUsers;
            detail.Sales  = sales;
            return(View(detail));
        }
コード例 #2
0
        public ActionResult EditModel(int id)
        {
            JivivContext context = new JivivContext();
            var          model   = context.Models.Single(x => x.Id == id);

            return(View(model));
        }
コード例 #3
0
        public ActionResult EditBrand(int id)
        {
            JivivContext context = new JivivContext();
            var          brand   = context.Brands.Single(x => x.Id == id);

            return(View(brand));
        }
コード例 #4
0
        public ActionResult BrandDetail()
        {
            JivivContext context = new JivivContext();
            var          brands  = context.Brands.ToList();

            return(View(brands));
        }
コード例 #5
0
        public ActionResult SellCar(int?brand, int?model, decimal?price)
        {
            JivivContext context = new JivivContext();
            var          brands  = context.Brands.ToList();
            var          models  = context.Models.Where(x => x.BrandId == brand).ToList();

            ViewBag.Brands = new SelectList(brands, "Id", "Name");
            ViewBag.Models = new SelectList(models, "Id", "Name");
            if (price == null)
            {
                ViewBag.Message = "Please enter price";
            }
            if (brand != null && model != null && price != null)
            {
                Sale sale = new Sale();
                sale.BrandId = brand ?? default(int);
                sale.ModelId = model ?? default(int);
                sale.UserId  = Convert.ToInt32(Session["userId"]);
                sale.Price   = price ?? 0;
                context.Sales.Add(sale);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #6
0
        public ActionResult CreateModel()
        {
            JivivContext context = new JivivContext();
            var          brands  = context.Brands.ToList();

            ViewBag.brandName = new SelectList(brands, "Id", "Name");
            return(View());
        }
コード例 #7
0
        public ActionResult ModelDetail(int?brand)
        {
            JivivContext context = new JivivContext();
            var          models  = context.Models.Where(x => x.BrandId == brand).ToList();
            var          brands  = context.Brands.ToList();

            ViewBag.Brands = new SelectList(brands, "Id", "Name");
            return(View(models));
        }
コード例 #8
0
 public ActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         JivivContext context = new JivivContext();
         context.Users.Add(user);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #9
0
 public ActionResult CreateBrand(Brand brand)
 {
     if (ModelState.IsValid)
     {
         JivivContext context = new JivivContext();
         context.Brands.Add(brand);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #10
0
 public ActionResult CreateModel(CarModel model)
 {
     if (ModelState.IsValid)
     {
         JivivContext context = new JivivContext();
         context.Models.Add(model);
         context.SaveChanges();
         return(RedirectToAction("ModelDetail", new { @brand = model.BrandId }));
     }
     return(View());
 }
コード例 #11
0
 public ActionResult EditBrand(Brand brand)
 {
     if (ModelState.IsValid)
     {
         JivivContext context      = new JivivContext();
         var          updatedBrand = context.Brands.Find(brand.Id);
         updatedBrand.Name = brand.Name;
         context.SaveChanges();
         return(RedirectToAction("BrandDetail"));
     }
     return(View(brand));
 }
コード例 #12
0
 public ActionResult EditModel(CarModel mod)
 {
     if (ModelState.IsValid)
     {
         JivivContext context      = new JivivContext();
         var          updatedModel = context.Models.Find(mod.Id);
         updatedModel.Name = mod.Name;
         context.SaveChanges();
         return(RedirectToAction("ModelDetail", new { @brand = mod.BrandId }));
     }
     return(View());
 }
コード例 #13
0
 public ActionResult DeleteModel(int id)
 {
     if (ModelState.IsValid)
     {
         JivivContext context      = new JivivContext();
         var          deletedValue = context.Models.Find(id);
         int          brandId      = deletedValue.BrandId;
         context.Models.Remove(deletedValue);
         context.SaveChanges();
         return(RedirectToAction("ModelDetail", new { @brand = brandId }));
     }
     return(View());
 }
コード例 #14
0
 public ActionResult DeleteBrand(int id)
 {
     if (ModelState.IsValid)
     {
         JivivContext context = new JivivContext();
         var          models  = context.Models.Where(x => x.BrandId == id).ToList();
         foreach (var mod in models)
         {
             context.Models.Remove(mod);
             context.SaveChanges();
         }
         var deletedValue = context.Brands.Find(id);
         context.Brands.Remove(deletedValue);
         context.SaveChanges();
         return(RedirectToAction("BrandDetail"));
     }
     return(View());
 }
コード例 #15
0
        public ActionResult UserProfile(int id)
        {
            var          detail    = new DetailSaleInformation();
            var          lstBrands = new List <Brand>();
            var          lstModels = new List <CarModel>();
            JivivContext context   = new JivivContext();
            var          sales     = context.Sales.Where(x => x.UserId == id).ToList();

            foreach (var item in sales)
            {
                lstBrands.Add(context.Brands.Find(item.BrandId));
                lstModels.Add(context.Models.Find(item.ModelId));
            }
            detail.Brands = lstBrands;
            detail.Models = lstModels;
            detail.Sales  = sales;
            return(View(detail));
        }
コード例 #16
0
 public ActionResult Index(User user)
 {
     if (ModelState.IsValid)
     {
         JivivContext context = new JivivContext();
         try
         {
             var loginUser = context.Users.Single(x => x.Username == user.Username && x.Password == user.Password);
             Session["userId"] = loginUser.Id;
             ViewBag.Message   = null;
             return(RedirectToAction("UserProfile", "Sale", new { @id = loginUser.Id }));
         } catch (Exception)
         {
             ViewBag.Message = "Incorrect username and / or password";
             return(View());
         }
     }
     return(View());
 }