コード例 #1
0
        public ActionResult EditBrand([Bind(Include = "ID,Name,MetaTitleImage,CreateDate,CreateBy,ModifiedDate,ModifiedBy,Category_ID,Status")] Brand model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var dao = new BrandDao();

                var a        = new Brand();
                var path     = "";
                var filename = "";
                if (image != null)
                {
                    filename = DateTime.Now.ToString("dd-MM-yy-hh-mm-ss-") + image.FileName;
                    path     = Path.Combine(Server.MapPath("~/Image"), filename);
                    image.SaveAs(path);
                    model.Image = filename;
                }
                //else
                //{

                //    content.Image = "~/Image/logo.png";
                //}
                model.Name        = model.Name;
                model.CreateDate  = Convert.ToDateTime(DateTime.UtcNow.ToLocalTime());
                model.MetaTitle   = StringHelper.ToUnsignString(model.Name);
                model.Category_ID = model.Category_ID;
                model.Status      = Convert.ToBoolean(true);
                var result = dao.Update(model);
                if (result)
                {
                    SetAlert("Sửa thành công", "success");
                    ViewBag.Success = "Cập nhật thành công";
                    model           = new Brand();
                    return(RedirectToAction("Index", "Brand"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật ko thành công");
                }
            }
            SetViewBag(model.Category_ID);
            return(View());
        }
コード例 #2
0
        public ActionResult Edit(Brand entity)
        {
            if (ModelState.IsValid)
            {
                var brandDao = new BrandDao();
                entity.Name = entity.Name.Trim();
                int result = brandDao.Update(entity);
                if (result == 1)
                {
                    ShowNotify("Update successfully", "success");
                    return(RedirectToAction("Index", "Brand"));
                }
                else if (result == -1)
                {
                    ShowNotify("This name already exists", "error");
                }
                else if (result == 0)
                {
                    ShowNotify("System error", "error");
                }
            }

            return(View("Edit"));
        }