Exemple #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            var product = new DAL.Repository.ProductRepository()
                          .GetById(id)
                          .FirstOrDefault();

            new DAL.Repository.ProductRepository()
            .Remove(product);

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        // GET: Products
        public ActionResult Index()
        {
            var products = new DAL.Repository.ProductRepository()
                           .GetAll()
                           .GroupBy(p => p.ProductName.Substring(0, 1))
                           .Select(p => new { k = p.Key, value = p })
                           .ToDictionary(
                p => p.k,
                p => p.value.Select(
                    x => new Models.ProductMVC()
            {
                Id = x.Id, Name = x.ProductName
            }));

            return(View(products));
        }
Exemple #3
0
        public ActionResult Edit([Bind(Include = "Id,Name")] Models.ProductMVC product)
        {
            if (ModelState.IsValid)
            {
                var item = new DAL.Repository.ProductRepository()
                           .GetById(product.Id)
                           .FirstOrDefault();

                if (item != null)
                {
                    item.ProductName = product.Name;
                    new DAL.Repository.ProductRepository()
                    .Update(item);

                    return(RedirectToAction("Index"));
                }
            }
            return(View(product));
        }
Exemple #4
0
        // GET: Products/Edit/5

        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var productId = id ?? default(int);

            var product = new DAL.Repository.ProductRepository()
                          .GetById(productId).Select(x => new Models.ProductMVC()
            {
                Id = x.Id, Name = x.ProductName
            })
                          .FirstOrDefault();

            if (product == null)
            {
                return(HttpNotFound());
            }
            return(View(product));
        }