コード例 #1
0
        public async Task <IActionResult> CategoryUpdate(CategoryModel cm, IList <IFormFile> files)
        {
            bool _boolean = false;

            ServiceReference_Category.Category c = await cs.findCategorybyIdAsync(cm.CategoryId);

            c.CategoryId   = cm.CategoryId;
            c.CategoryName = cm.CategoryName;
            c.ImageCate    = cm.ImageCate;
            c.ParentId     = cm.ParentId;
            c.StatusCate   = cm.StatusCate;
            if (files.Count > 0)
            {
                string path     = _host.WebRootPath + @"/images/";
                string filename = "";
                foreach (IFormFile f in files)
                {
                    filename = f.FileName;

                    FileStream fs = System.IO.File.Create(path + filename);
                    f.CopyTo(fs);
                    fs.Flush();
                }
                c.ImageCate = filename;
                _boolean    = await cs.updateCategoryAsync(c);
            }
            else
            {
                _boolean = await cs.updateCategoryAsync(c);
            }
            if (_boolean)
            {
                flag    = "success";
                message = "Update category success";
            }
            else
            {
                flag    = "error";
                message = "Update category unsuccess.";
            }
            return(RedirectToAction("CategoryEdit/" + c.CategoryId));
        }