Пример #1
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var category = context.Category.First(c => c.Id == id);
             TryUpdateModel(category, new[]
                                          {
                                              "Name",
                                              "Title", 
                                              "Description", 
                                              "BottomDescription", 
                                              "BottomDescriptionTitle",
                                              "ShowOnMainPage",
                                              "PageTitle"
                                          });
             context.SaveChanges();
             return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name });
         }
     }
     catch
     {
         return View();
     }
 }
Пример #2
0
        public ActionResult Edit(int id, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContainer())
            {
                var article = context.Article.First(a => a.Id == id);
                TryUpdateModel(article, new[] { "Name", "Title", "Date", "Description", "PageTitle" });
                article.OldPrice = HttpUtility.HtmlDecode(form["OldPrice"]);
                article.NewPrice = HttpUtility.HtmlDecode(form["NewPrice"]);
                article.Text = HttpUtility.HtmlDecode(form["Text"]);

                if (fileUpload != null)
                {
                    if (!string.IsNullOrEmpty(article.ImageSource))
                    {

                        IOHelper.DeleteFile("~/Content/Images", article.ImageSource);
                        foreach (var thumbnail in SiteSettings.Thumbnails)
                        {
                            IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, article.ImageSource);
                        }
                    }
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    fileUpload.SaveAs(filePath);
                    article.ImageSource = fileName;
                }

                context.SaveChanges();
                return RedirectToAction("Articles","Home",new{area=""});
            }
        }
Пример #3
0
 public ActionResult Create(int? parentId, FormCollection collection)
 {
     using (var context = new SiteContainer())
     {
         var category = new Category();
         TryUpdateModel(category, new[]
                                          {
                                              "Name",
                                              "Title", 
                                              "Description", 
                                              "BottomDescription", 
                                              "BottomDescriptionTitle",
                                              "ShowOnMainPage",
                                              "PageTitle"
                                          });
         if (parentId.HasValue)
         {
             var parent = context.Category.First(c => c.Id == parentId);
             parent.Children.Add(category);
         }
         else
         {
             context.AddToCategory(category);
         }
         context.SaveChanges();
         return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name });
     }
 }
Пример #4
0
        public ActionResult Edit(int id, FormCollection collection, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var banner = context.Banner.First(b => b.Id == id);
                    TryUpdateModel(banner, new[] { "Description", "Link", "Price" });

                    if (fileUpload != null)
                    {
                        if (!string.IsNullOrEmpty(banner.ImageSource))
                        {

                            IOHelper.DeleteFile("~/Content/Images", banner.ImageSource);
                            foreach (var thumbnail in SiteSettings.Thumbnails)
                            {
                                IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, banner.ImageSource);
                            }
                        }
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        fileUpload.SaveAs(filePath);
                        banner.ImageSource = fileName;
                    }
                    context.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Пример #5
0
 public ActionResult Create(FormCollection collection, HttpPostedFileBase fileUpload)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             var banner = new Banner();
             TryUpdateModel(banner, new[] { "Description", "Link", "Price" });
             if (fileUpload != null)
             {
                 string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                 string filePath = Server.MapPath("~/Content/Images");
                 filePath = Path.Combine(filePath, fileName);
                 fileUpload.SaveAs(filePath);
                 banner.ImageSource = fileName;
             }
             context.AddToBanner(banner);
             context.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch
     {
         return View();
     }
 }
Пример #6
0
        public ActionResult Gallery(string id)
        {
            using (var context = new SiteContainer())
            {
                SiteModel model = new SiteModel(context, "gallery");
                
                model.Categories = context.Category.Include("Products").ToList();

                if (model.Categories.Any())
                {
                    model.Category = !string.IsNullOrEmpty(id)
                                         ? model.Categories.First(c => c.Name == id)
                                         : model.Categories.First(c => !c.SpecialCategory);

                    model.Products = model.Products.Where(p => p.CategoryId == model.Category.Id).ToList();
                    model.Title += " » " + model.Category.Title;
                }



                //model.Products = model.Products.Where(p => p.CategoryId == id).ToList();
                //model.Category = context.Category.First(c => c.Id == id);
                this.SetSeoContent(model);
                return View(model);
            }
        }
Пример #7
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var banner = context.Banner.First(b => b.Id == id);
         return View(banner);
     }
 }
Пример #8
0
 public ActionResult Index()
 {
     using (var context = new SiteContainer())
     {
         var banners = context.Banner.ToList();
         return View(banners);
     }
 }
Пример #9
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var category = context.Category.First(c => c.Id == id);
         return View(category);
     }
 }
Пример #10
0
        public WorksModel(SiteContainer context, int productId)
            : base(context, "gallery")
        {
            _context = context;

            Product = _context.Product.Include("Category").Include("ProductSizes").Include("ProductImages").First(p => p.Id == productId);
            Category = Product.Category;
        }
Пример #11
0
 public ActionResult Edit(string id)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Name == id);
         return View(content);
     }
 }
Пример #12
0
 public ActionResult Index()
 {
     using (var context = new SiteContainer())
     {
         var products = context.Product.Include("Category").ToList();
         return View(products);
     }
 }
Пример #13
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContainer())
     {
         var article = context.Article.First(a => a.Id == id);
         return View(article);
     }
 }
Пример #14
0
 public ActionResult WorkDetails(int id)
 {
     using (var context = new SiteContainer())
     {
         var model = new WorksModel(context, id);
         this.SetSeoContent(model);
         return View(model);
     }
 }
Пример #15
0
 public ActionResult ProductDetailsPopUp(int id, int? productImageId)
 {
     using (var context = new SiteContainer())
     {
         var model = new GalleryModel(context, null, id, productImageId);
         this.SetSeoContent(model);
         return PartialView(model);
     }
 }
Пример #16
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         var article = context.Article.First(a => a.Id == id);
         context.DeleteObject(article);
         context.SaveChanges();
         return RedirectToAction("Articles", "Home", new { area = "" });
     }
 }
Пример #17
0
 public ActionResult Articles()
 {
     using (var context = new SiteContainer())
     {
         SiteModel model = new SiteModel(context, "articles", true);
         this.SetSeoContent(model);
         ViewBag.CurrentMenuItemName = model.Content.Name;
         return View(model);
     }
 }
Пример #18
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var article = context.Article.First(a => a.Id == id);
         TryUpdateModel(article, new[] { "Name", "Title", "Date", "Description" });
         article.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Articles","Home",new{area=""});
     }
 }
Пример #19
0
        public ActionResult Edit(int id)
        {
            using (var context = new SiteContainer())
            {
                var categories = context.Category.ToList();
                ViewBag.Categories = categories.Select(category => new SelectListItem { Text = category.Title, Value = category.Id.ToString() }).ToList();

                var product = context.Product.First(p => p.Id == id);
                return View(product);
            }
        }
Пример #20
0
 public ActionResult ArticleDetails(string id)
 {
     using (var context = new SiteContainer())
     {
         var model = new SiteModel(context, "articles", true);
         this.SetSeoContent(model);
         model.Article = context.Article.First(a => a.Name == id);
         ViewBag.PageTitle = model.Article.PageTitle;
         ViewBag.CurrentMenuItemName = model.Content.Name;
         return View(model);
     }
 }
Пример #21
0
        public ActionResult Create(int id)
        {
            using (var context = new SiteContainer())
            {
                var category = context.Category.First(c => c.Id == id);

                var product = new Product { Category = category };
                //ViewBag.Categories = categories.Select(category => new SelectListItem {Text = category.Title, Value = category.Id.ToString()}).ToList();
                ViewBag.categoryId = id;
                return View(product);
            }
        }
Пример #22
0
 public ActionResult Edit(string id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Name == id);
         TryUpdateModel(content, new[] { "Title", "DescriptionTitle", "SeoDescription", "SeoKeywords", "PageTitle" });
         content.Description = HttpUtility.HtmlDecode(form["Description"]);
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new {area = "", id = content.Name});
     }
 }
Пример #23
0
 public ActionResult Index(string id)
 {
     using (var context = new SiteContainer())
     {
         SiteModel model = new SiteModel(context, id);
         this.SetSeoContent(model);
         ViewBag.SpecialCategoryName = context.Category.First(c => c.SpecialCategory).Name;
         ViewBag.CurrentMenuItemName = model.Content.Name;
         ViewBag.isHomePage = model.IsHomePage;
         return View(model);
     }
 }
Пример #24
0
 public ActionResult ProductDetails(int id)
 {
     using (var context = new SiteContainer())
     {
         var model = new GalleryModel(context, null, id);
         this.SetSeoContent(model);
         ViewBag.PageTitle = model.PageTitle;
         //ViewBag.CurrentCategoryId = model.Category.Id;
         ViewBag.CurrentProductId = model.Product.Id;
         return View(model);
     }
 }
Пример #25
0
        public ActionResult Create(int categoryId, FormCollection form)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = context.Category.First(c => c.Id == categoryId);
                    var product = new Product { Category = category, ImageSource = "" };
                    TryUpdateModel(product, new[] { "Title", "Discount", "Price", "Structure", "Consistence", "Producer", "Nap", "PageTitle" });

                    product.Description = HttpUtility.HtmlDecode(form["Description"]);
                    product.DiscountText = HttpUtility.HtmlDecode(form["DiscountText"]);

                    for (int i = 0; i < Request.Files.Count; i++)
                    {

                        var file = Request.Files[i];

                        if (file == null) continue;
                        if (string.IsNullOrEmpty(file.FileName)) continue;

                        var pi = new ProductImage();
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                        string filePath = Server.MapPath("~/Content/Images");


                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                        //file.SaveAs(filePath);

                        pi.ImageSource = fileName;
                        product.ProductImages.Add(pi);
                        if (string.IsNullOrEmpty(product.ImageSource))
                            product.ImageSource = pi.ImageSource;
                    }

                    context.AddToProduct(product);
                    context.SaveChanges();

                    if (category.SpecialCategory)
                    {
                        return RedirectToAction("OurWorks", "Home", new { area = "" });
                    }

                    return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name });
                }
            }
            catch (Exception ex)
            {
                return View(ViewBag.ErrorMessage = ex.Message);
            }
        }
Пример #26
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         var category = context.Category.Include("Products").First(c => c.Id == id);
         if (!category.Products.Any())
         {
             context.DeleteObject(category);
             context.SaveChanges();
         }
     }
     return RedirectToAction("Gallery", "Home", new { area = "" });
 }
Пример #27
0
 public ActionResult Create(int? categoryId)
 {
     using (var context = new SiteContainer())
     {
         var categories = context.Category.ToList();
         ViewBag.Categories = categories.Select(category => new SelectListItem {Text = category.Title, Value = category.Id.ToString()}).ToList();
         if(categoryId.HasValue)
         {
             ViewBag.categoryId = categoryId;
         }
         return View();
     }
 } 
Пример #28
0
        public ActionResult Create(FormCollection form)
        {

            using (var context = new SiteContainer())
            {
                var article = new Article { Name = "" };
                TryUpdateModel(article, new[] { "Name", "Title", "Date", "Description" });
                article.Text = HttpUtility.HtmlDecode(form["Text"]);
                context.AddToArticle(article);
                context.SaveChanges();
            }
            return RedirectToAction("Articles", "Home", new { area = "" });

        }
Пример #29
0
        public ActionResult Index(string id)
        {
            

            using (var context = new SiteContainer())
            {
                var model = new SiteModel(context, id);
                this.SetSeoContent(model);
                ViewBag.PageTitle = model.PageTitle;
                ViewBag.CurrentMenuItemName = model.Content.Name;
                ViewBag.isHomePage = model.IsHomePage;
                return View(model);
            }
        }
Пример #30
0
 public ActionResult Create(FormCollection collection)
 {
     using (var context = new SiteContainer())
     {
         var category = new Category();
         TryUpdateModel(category, new[]
                                          {
                                              "Name",
                                              "Title", 
                                              "Description", 
                                              "BottomDescription", 
                                              "BottomDescriptionTitle"
                                          });
         context.AddToCategory(category);
         context.SaveChanges();
         return RedirectToAction("Gallery", "Home", new { area = "", id = category.Name });
     }
 }