예제 #1
0
        public ActionResult Search(string search, string sort)
        {
            var model = new SkorIndexViewModel();

            model.Search = search;

            if (!string.IsNullOrEmpty(search))
            {
                using (var db = new SkorModelDB())
                {
                    model.SkorList.AddRange(db.SkorTable
                                            .Select(x => new SkorIndexViewModel.SkorListViewModel
                    {
                        ID          = x.SkorId,
                        Name        = x.Name,
                        Model       = x.Model,
                        Size        = x.Size,
                        Color       = x.Color,
                        Price       = x.Price,
                        Description = x.Description,
                        CategoryId  = x.CategoryId
                    }));

                    model.SkorList = model.SkorList.Where(x => x.Name.ToUpper().Contains(search.ToUpper())).ToList();

                    model = Sort(model, sort);

                    return(View("Search", model));
                }
            }

            return(View("Search", model));
        }
예제 #2
0
        public ActionResult Create(SkoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new SkorModelDB())
            {
                var skor = new SkorModel
                {
                    SkorId      = model.SkorId,
                    Name        = model.Name,
                    Model       = model.Model,
                    Color       = model.Color,
                    Size        = model.Size,
                    Price       = model.Price,
                    Description = model.Description,
                    CategoryId  = model.CategoryId
                };

                db.SkorTable.Add(skor);
                db.SaveChanges();
                return(RedirectToAction("Index", "Skor", new { id = model.CategoryId }));
            }
        }
예제 #3
0
        public ActionResult Edit(SkoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", new { id = model.CategoryId }));
            }

            using (var db = new SkorModelDB())
            {
                var product = db.SkorTable.FirstOrDefault(x => x.CategoryId == model.CategoryId);

                product.SkorId      = model.SkorId;
                product.Name        = model.Name;
                product.Model       = model.Model;
                product.Color       = model.Color;
                product.Size        = model.Size;
                product.Price       = model.Price;
                product.Description = model.Description;
                product.CategoryId  = model.CategoryId;


                db.SaveChanges();
                return(RedirectToAction("Index", new { id = product.CategoryId }));
            }
        }
예제 #4
0
 public ActionResult Delete(int?id)
 {
     using (var db = new SkorModelDB())
     {
         var category = db.CategoriesTable.Find(id);
         var model    = new CategoryViewModel
         {
             CategoryId   = category.CategoryId,
             CategoryName = category.CategoryName
         };
         return(View(model));
     }
 }
예제 #5
0
        public ActionResult Index()
        {
            var model = new CategoryIndexViewModel();

            using (var db = new SkorModelDB())
            {
                model.Categories.AddRange(db.CategoriesTable.Select(c => new CategoryIndexViewModel.CategoryListViewModel
                {
                    CategoryId   = c.CategoryId,
                    CategoryName = c.CategoryName
                }));
            }
            return(View(model));
        }
예제 #6
0
        public ActionResult Create(int?id)
        {
            var model = new SkoViewModel {
                CategoryId = (int)id
            };

            using (var db = new SkorModelDB())
            {
                model.CategoryName = string.Join("", db.CategoriesTable.Where(x => x.CategoryId == id).Select(x => x.CategoryName));
                model.CategoryId   = (int)id;
            }

            return(View(model));
        }
예제 #7
0
        public ActionResult Edit(int?id)
        {
            using (var db = new SkorModelDB())
            {
                var category = db.CategoriesTable.FirstOrDefault(p => p.CategoryId == id);

                var model = new CategoryViewModel

                {
                    CategoryId   = category.CategoryId,
                    CategoryName = category.CategoryName
                };
                return(View(model));
            }
        }
예제 #8
0
        public ActionResult Edit(CategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new SkorModelDB())
            {
                var category = db.CategoriesTable.FirstOrDefault(r => r.CategoryId == model.CategoryId);
                category.CategoryId   = model.CategoryId;
                category.CategoryName = model.CategoryName;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
예제 #9
0
 public ActionResult DeleteConfirm(int?id)
 {
     if (id == null || id == 0)
     {
         return(RedirectToAction("Index"));
     }
     using (var db = new SkorModelDB())
     {
         var obj = db.CategoriesTable.Find(id);
         if (obj != null)
         {
             db.CategoriesTable.Remove(obj);
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
 }
예제 #10
0
        public List <SelectListItem> DropDownCategories()
        {
            var model = new SkoViewModel();

            model.CategoryDropDownList = new List <SelectListItem>();
            using (var db = new SkorModelDB())
            {
                foreach (var category in db.CategoriesTable)
                {
                    model.CategoryDropDownList.Add(new SelectListItem {
                        Value = category.CategoryId.ToString(), Text = category.CategoryName
                    });
                }

                return(model.CategoryDropDownList);
            }
        }
예제 #11
0
        public ActionResult Create(CategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new SkorModelDB())
            {
                var cat = new Models.CategoryModel
                {
                    CategoryName = model.CategoryName
                };

                db.CategoriesTable.Add(cat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
예제 #12
0
        public ActionResult ViewSkor(int id, string sort)
        {
            var model = new SkoViewModel();

            using (var db = new SkorModelDB())
            {
                var sko = db.SkorTable.Find(id);
                model.CategoryId   = sko.CategoryId;
                model.CategoryName = sko.Category.CategoryName;
                model.Name         = sko.Name;
                model.Model        = sko.Model;
                model.Color        = sko.Color;
                model.Size         = sko.Size;
                model.Price        = sko.Price;
                model.Description  = sko.Description;

                return(View(model));
            }
        }
예제 #13
0
        public ActionResult Delete(int?id)
        {
            using (var db = new SkorModelDB())
            {
                var prod  = db.SkorTable.Find(id);
                var model = new SkoViewModel
                {
                    SkorId      = prod.SkorId,
                    Name        = prod.Name,
                    Model       = prod.Model,
                    Color       = prod.Color,
                    Size        = prod.Size,
                    Price       = prod.Price,
                    Description = prod.Description
                };

                return(View(model));
            }
        }
예제 #14
0
        public ActionResult AllSkor()
        {
            var model = new SkorIndexViewModel();

            using (var db = new SkorModelDB())
            {
                model.SkorList.AddRange(db.SkorTable.Select(x => new SkorIndexViewModel.SkorListViewModel
                {
                    ID          = x.SkorId,
                    Name        = x.Name,
                    Model       = x.Model,
                    Color       = x.Color,
                    Size        = x.Size,
                    Price       = x.Price,
                    Description = x.Description,
                    CategoryId  = x.CategoryId
                }));

                return(View(model));
            }
        }
예제 #15
0
        public ActionResult Edit(int?id)
        {
            using (var db = new SkorModelDB())
            {
                var product = db.SkorTable.Find(id);
                var model   = new SkoViewModel
                {
                    CategoryName         = product.Category.CategoryName,
                    CategoryId           = product.CategoryId,
                    SkorId               = product.SkorId,
                    Name                 = product.Name,
                    Model                = product.Model,
                    Color                = product.Color,
                    Size                 = product.Size,
                    Price                = product.Price,
                    Description          = product.Description,
                    CategoryDropDownList = DropDownCategories()
                };

                return(View(model));
            }
        }
예제 #16
0
        public ActionResult Index(int id, string sort)
        {
            var model = new SkorIndexViewModel();

            using (var db = new SkorModelDB())
            {
                model.CategoryName = string.Join("", db.CategoriesTable.Where(x => x.CategoryId == id).Select(x => x.CategoryName));
                model.CategoryId   = id;
                model.SkorList.AddRange(db.SkorTable.Select(p => new SkorIndexViewModel.SkorListViewModel
                {
                    ID          = p.SkorId,
                    Name        = p.Name,
                    Model       = p.Model,
                    Color       = p.Color,
                    Size        = p.Size,
                    Price       = p.Price,
                    Description = p.Description,
                    CategoryId  = p.CategoryId
                }).Where(p => p.CategoryId == id));

                model = Sort(model, sort);
                return(View(model));
            }
        }