Exemplo n.º 1
0
        //protected void btnAdd_Click(object sender, EventArgs e)
        //{
        //    if(!IsPostBack)
        //    {
        //        lblModalTitle.Text = "Add new category";
        //        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
        //        upModal.Update();
        //    }
        //}

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if(txtCateID.Text == "")
            {
                Category cate = new Category();
                cate.CategoryName = txtCateName.Text;
                cate.Description = txtDescription.Text;
                if (txtPicture.HasFile == true)
                {
                    cate.Picture = txtPicture.FileBytes;
                }
                Cate.Add(cate);
            }
            else
            {
                Category cate = new Category();
                cate.CategoryID = int.Parse(txtCateID.Text);
                cate.CategoryName = txtCateName.Text;
                cate.Description = txtDescription.Text;
                if (txtPicture.HasFile == true)
                {
                    cate.Picture = txtPicture.FileBytes;
                }
                Cate.Edit(cate);
            }

            ReloadCateGrid();
            ScriptManager.RegisterStartupScript(this, GetType(), "CloseAlert", "CloseAlert();", true); 
            
        }
Exemplo n.º 2
0
 //
 // GET: /Product/
 public ActionResult Index(int? page=1, int? categoryID=0)
 {
     List<Category> lsCate = new List<Category>();
     var all = new Category { CategoryID = 0, CategoryName = "All", Description = "Load all category" };
     lsCate.Add(all);
     lsCate.AddRange(_cate.GetAll()); // _uow.Repository<Category>().GetAll().ToList());
     var selectedValue = lsCate.Find(c => c.CategoryID == categoryID);
     ViewBag.CategoryID = new SelectList(lsCate, "CategoryID", "CategoryName", selectedValue);
     ViewBag.SelectedCategoryID = categoryID;
     var products = _prod.GetAll(); // _uow.Repository<Product>().GetAll();
     pageSize = 3;
     int pageNumber = (page ?? 1);
     
     if (categoryID != 0)
     {
         var rsl = products.OrderBy(i => i.ProductID).Where(p => p.CategoryID == categoryID).ToPagedList(pageNumber, pageSize);
         return View(rsl);
     }
     else
     {
         try
         {
             var rsl = products.OrderBy(i => i.ProductID).ToPagedList(pageNumber, pageSize);
             iRetry = 0;
             return View(rsl);
         }
         catch(Exception ex)
         {
             if (iRetry < 3)
             {
                 iRetry++;
                 return Index(page, categoryID);
             }
             else
             {
                 iRetry = 0;
                 return View();
             }                    
         }                
     }
 }
Exemplo n.º 3
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                if(Request.Files.Count >0 )
                {
                    var file = Request.Files["txtpicture"];
                    if(file != null && file.ContentLength > 0 )
                    {
                        var red = new BinaryReader(file.InputStream);
                        var filed = red.ReadBytes(file.ContentLength);
                        //var content = Convert.ToBase64String(filed);
                        //var fileName = Path.GetFileName(file.FileName);
                        //var path = Path.Combine(Server.MapPath("~"),fileName);
                        //file.SaveAs(path);
                        category.Picture = filed;
                    }
                }
                _cate.Add(category);
                return RedirectToAction("Index");
            }

            return View(category);
        }
Exemplo n.º 4
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         _cate.Edit(category);
         return RedirectToAction("Index");
     }
     return View(category);
 }