Exemple #1
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 }));
            }
        }
Exemple #2
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 }));
            }
        }
Exemple #3
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));
        }
Exemple #4
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);
            }
        }
Exemple #5
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));
            }
        }
Exemple #6
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));
            }
        }
Exemple #7
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));
            }
        }