예제 #1
0
        public ActionResult Create(Brand model, HttpPostedFileBase fileUpload, int brandId)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var brandGroup = context.BrandGroup.First(b => b.Id == brandId);

                    var cache = new Brand
                                    {
                                        Name = SiteHelper.UpdatePageWebName(model.Name), 
                                        Description = model.Description,
                                        SortOrder = model.SortOrder
                                    };


                    if (fileUpload != null)
                    {
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload, 500);
                        //fileUpload.SaveAs(filePath);
                        cache.ImageSource = fileName;

                        cache.BrandGroup = brandGroup;

                        context.AddToBrand(cache);

                        var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                        if (lang != null)
                        {
                            CreateOrChangeContentLang(context, model, cache, lang);
                        }
                    }
                    return RedirectToAction("BrandGroupDetails", "Home", new { area = "BrandCatalogue",id=brandGroup.Name });
                }
            }
            catch
            {
                return View();
            }
        }