示例#1
0
        public async Task <ActionResult> Create([Bind(Include = "CategoryId,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
示例#2
0
        public async Task <ActionResult> Create(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Images";

                if (view.ImageFile != null)
                {
                    pic = FileHerpels.FileUpload(view.ImageFile, folder);
                    pic = string.Format("{0}/{1}", folder, pic);
                }
                var productoView = ToProductView(view);
                productoView.Image = pic;
                db.Products.Add(productoView);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories.OrderBy(c => c.Description), "CategoryId", "Description", view.CategoryId);
            return(View(view));
        }