Ejemplo n.º 1
0
        public ActionResult Create(Brand entity)
        {
            if (ModelState.IsValid)
            {
                var brandDao = new BrandDao();

                entity.Name = entity.Name.Trim();
                long result = brandDao.Insert(entity);
                if (result > 0)
                {
                    ShowNotify("Update successfully", "success");
                    return(RedirectToAction("Index", "Brand"));
                }
                else if (result == -1)
                {
                    ShowNotify("This name already exists", "error");
                }
                else
                {
                    ShowNotify("System error", "error");
                }
            }

            return(View("Create"));
        }
Ejemplo n.º 2
0
        public ActionResult CreateBrand([Bind(Include = "ID,Name,MetaTitle,Image,CreateDate,CreateBy,Category_ID,Status")] Brand brand, HttpPostedFileBase image)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao      = new BrandDao();
                    var filename = "";
                    var path     = "";
                    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);
                        brand.Image = filename;
                    }
                    //else
                    //{

                    //    content.Image = "~/Image/logo.png";
                    //}
                    brand.Name        = brand.Name;
                    brand.CreateDate  = Convert.ToDateTime(DateTime.UtcNow.ToLocalTime());
                    brand.MetaTitle   = StringHelper.ToUnsignString(brand.Name);
                    brand.Category_ID = brand.Category_ID;
                    brand.Status      = Convert.ToBoolean(true);
                    var id = dao.Insert(brand);
                    if (id > 0)
                    {
                        SetAlert("Thêm mới thành thành công", "success");
                        ViewBag.Success = "Thêm thành công";
                        brand           = new Brand();
                        return(RedirectToAction("Index", "Brand"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm mới ko thành công");
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                throw e;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            SetViewBag();
            return(View(brand));
        }