Beispiel #1
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile)
        {
            try
            {
                using (var context = new ShopContainer())
                {

                    var brand = new Brand
                                    {
                                        Name = form["Name"], 
                                        Title = form["Title"],
                                        Description = form["Description"], 
                                        SeoDescription = form["SeoDescription"], 
                                        SeoKeywords = form["SeoKeywords"]
                                    };
                    if (uploadFile != null)
                    {
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        uploadFile.SaveAs(filePath);
                        brand.Logo = fileName;
                    }
                    context.AddToBrand(brand);
                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }