Exemplo n.º 1
0
        public ActionResult Create(Category model, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = new Category
                    {
                        Name = SiteHelper.UpdatePageWebName(model.Name),
                        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);
                        cache.ImageSource = fileName;
                    }

                    context.AddToCategory(cache);

                    var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                    if (lang != null)
                    {
                        CreateOrChangeContentLang(context, model, cache, lang);
                    }

                    return RedirectToAction("Index", "Category", new { area = "FactoryCatalogue" });
                }
            }
            catch
            {
                return View();
            }
        }