Ejemplo n.º 1
0
        public JsonResult AddCategory()
        {
            try
            {
                CategoryRepository categoryRepo = new CategoryRepository();
                Category cata = new Category();

                cata.Name = Request.Form["Name"];
                cata.IsActive = true;
                cata.Description = Request.Form["Description"];
                cata.DateCreated = DateTime.Now;

                categoryRepo.Add(cata);

                return Json(new
                {
                    Id = cata.Id,
                    Name = cata.Name,
                    error = false
                });
            }
            catch
            {
                return Json(new
                {
                    error = true
                });
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the main page for categories
 /// /Category/
 /// </summary>
 /// <returns>main page view</returns>
 public ActionResult Index()
 {
     var categories = new CategoryRepository().GetAll();
     return View(categories);
     //return View(new CategoryRepository().GetAll());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the details model for a specific category id
        /// /Details/XXXXX
        /// </summary>
        /// <param name="id">category id to show details for</param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            var category = new CategoryRepository().Get(id);

            return View(category);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Edit a product and return results
 /// </summary>
 /// <returns>Result of the update</returns>
 public JsonResult EditProduct()
 {
     try
     {
         ProductRepository productRepo = new ProductRepository();
         CategoryRepository categoryRepo = new CategoryRepository();
         Product product = productRepo.Get(int.Parse(Request.Form["ProductId"]));
         product.Name = Request.Form["Name"];
         product.Unit = Request.Form["Unit"];
         product.Category = categoryRepo.Get(int.Parse(Request.Form["CategoryId"]));
         product.Price = decimal.Parse(Request.Form["Price"]);
         return Json(new
         {
             error = false
         });
     }
     catch
     {
         return Json(new
         {
             error = true
         });
     }
 }
Ejemplo n.º 5
0
        public JsonResult DeleteCategory()
        {
            try
            {
                CategoryRepository categoryRepo = new CategoryRepository();
                Category category = categoryRepo.Get(int.Parse(Request.Form["Category"]));
                category.IsActive = false;

                return Json(new
                {
                    error = false
                });
            }
            catch
            {
                return Json(new
                {
                    error = true
                });
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add product to the system
        /// </summary>
        /// <returns>Result of the add</returns>
        public JsonResult AddProduct()
        {
            try
            {
                CategoryRepository categoryRepo = new CategoryRepository();
                ProductRepository productRepo = new ProductRepository();

                Product product = new Product();
                product.Name = Request.Form["Name"];
                product.Unit = Request.Form["Unit"];
                product.Category = categoryRepo.Get(int.Parse(Request.Form["CategoryId"]));
                product.Price = Decimal.Parse(Request.Form["Price"]);
                product.QuantityOnHand = int.Parse(Request.Form["QuantityOnHand"]);
                product.Counter = 0;
                product.IsActive = true;

                productRepo.Add(product);

                return Json(new
                {
                    error = false,
                    Name = product.Name,
                    Id = product.Id
                });
            }
            catch
            {
                return Json(new
                {
                    error = true
                });
            }
        }