コード例 #1
0
ファイル: CatalogueViewModel.cs プロジェクト: fathurxzz/aleqx
        public CatalogueViewModel(SiteContext context, string category, string product, int? page)
            : base(context, category == "" ? "" : null)
        {
            UpdateMainMenu(category, product);
            
            if(!string.IsNullOrEmpty(category))
            {
                Category = context.Category.Include("Products").First(c => c.Name == category);
                PageTitle += " » " + Category.Title;
                SeoDescription = Category.SeoDescription;
                SeoKeywords = Category.SeoKeywords;
                Title = Category.Title;
                TitleToCategory = Category.TitleToCategory;

                TotalProductsCount = Category.Products.Count();
                Products = ApplyPaging(Category.Products, page).ToList();
            }

            if(!string.IsNullOrEmpty(product))
            {
                Product = context.Product.Include("Category").Include("ProductItems").First(p => p.Name == product);
                SeoDescription = Product.SeoDescription;
                SeoKeywords = Product.SeoKeywords;
                PageTitle += " » " + Product.Title;
                Title = Product.Title;
            }
        }
コード例 #2
0
ファイル: ProductController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Create(int categoryId, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContext())
            {
                var category = context.Category.First(c => c.Id == categoryId);
                var product = new Product{SortOrder = 0};
                TryUpdateModel(product, new[] { "Name","Date", "Title",/* "SortOrder",*/ "SeoDescription", "SeoKeywords" });
                product.Description = HttpUtility.HtmlDecode(form["Description"]);
                product.Category = category;

                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);
                    fileUpload.SaveAs(filePath);
                    product.ImageSource = fileName;
                }

                context.AddToProduct(product);
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", category = category.Name, product = product.Name });
            }
        }
コード例 #3
0
ファイル: SiteViewModel.cs プロジェクト: fathurxzz/aleqx
        public SiteViewModel(SiteContext context, string contentName)
        {
            PageTitle = "Студия Евгения Миллера";
            var categories = context.Category;
            Menu = InitializeMainMenu(categories);

            if (!string.IsNullOrEmpty(contentName))
            {
                Content = context.Content.First(c => c.Name == contentName);
            }
            else if (contentName == "")
            {
                Content = context.Content.First(c => c.HomePage);
                IsHomePage = true;
            }
            
            if(Content!=null)
            {
                PageTitle += " » " + Content.Title;
                SeoDescription = Content.SeoDescription;
                SeoKeywords = Content.SeoKeywords;
                Title = Content.Title;
            }

            if (contentName=="secretlink")
            {
                SecretImages = context.SecretImage.ToList();
            }

        }
コード例 #4
0
ファイル: ProductController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Edit(int id, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContext())
            {
                var product = context.Product.Include("Category").First(p => p.Id == id);
                TryUpdateModel(product, new[] { "Name", "Date", "Title",/* "SortOrder",*/ "SeoDescription", "SeoKeywords" });
                product.Description = HttpUtility.HtmlDecode(form["Description"]);
                if (fileUpload != null)
                {
                    if (!string.IsNullOrEmpty(product.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                    }

                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload);
                    fileUpload.SaveAs(filePath);
                    product.ImageSource = fileName;
                }
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", category = product.Category.Name, product=product.Name });
            }
        }
コード例 #5
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContext())
     {
         var content = context.Content.First(c => c.Id == id);
         return View(content);
     }
 }
コード例 #6
0
ファイル: CategoryController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContext())
     {
         var category = context.Category.First(c => c.Id == id);
         return View(category);
     }
 }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult English()
 {
     using (var context = new SiteContext())
     {
         var model = new SiteViewModel(context, null);
         ViewBag.PageTitle = model.PageTitle;
         ViewBag.isHomePage = false;
         return View(model);
     }
 }
コード例 #8
0
ファイル: ProductController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Create(int id)
 {
     using (var context = new SiteContext())
     {
         ViewBag.CategoryId = id;
         ViewBag.CategoryName = context.Category.First(c => c.Id == id).Name;
         //var max = context.Product.Max(p => p.SortOrder);
         return View(new Product {/*SortOrder = max + 1,*/Date = DateTime.Now});
     }
 }
コード例 #9
0
ファイル: CategoryController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Create()
 {
     using (var context = new SiteContext())
     {
         int max=0;
         if(context.Category.Any())
         max = context.Category.Max(c => c.SortOrder);
         return View(new Category {SortOrder = max + 1});
     }
 }
コード例 #10
0
ファイル: CategoryController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContext())
     {
         var category = context.Category.First(c => c.Id == id);
         TryUpdateModel(category, new[] { "Name", "Title", "TitleToCategory", "SeoDescription", "SeoKeywords", "SortOrder" });
         category.Description = HttpUtility.HtmlDecode(form["Description"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Home", new { area = "", category = category.Name });
     }
 }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult SiteContent(string id)
 {
     using (var context = new SiteContext())
     {
         var model = new SiteViewModel(context, id);
         this.SetSeoContent(model);
         ViewBag.PageTitle = model.PageTitle;
         ViewBag.isHomePage = false;
         return View("Content", model);
     }
 }
コード例 #12
0
ファイル: ProductController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Edit(int id)
        {
            using (var context = new SiteContext())
            {
                var product = context.Product.Include("Category").First(p => p.Id == id);
                //TryUpdateModel(product, new[] { "Name", "Title", "Description", "SortOrder", "SeoDescription", "SeoKeywords" });

                //context.SaveChanges();
                return View(product);
            }
        }
コード例 #13
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContext())
     {
         var content = context.Content.First(c => c.Id == id);
         TryUpdateModel(content, new[] {"Title", "SeoDescription", "SeoKeywords"});
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index","Home",new{area=""});
     }
 }
コード例 #14
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContext())
     {
         var image = context.SecretImage.First(i => i.Id == id);
         ImageHelper.DeleteImage(image.ImageSource);
         ImageHelper.DeleteImage(image.PreviewImageSource);
         context.DeleteObject(image);
         context.SaveChanges();
         return RedirectToAction("SiteContent", "Home", new { id = "secretlink", area = "" });
     }
 }
コード例 #15
0
 public ActionResult Edit(int id)
 {
     using (var context = new SiteContext())
     {
         var pi = context.ProductItem.Include("Product").First(p => p.Id == id);
         var productId = pi.Product.Id;
         var product = context.Product.Include("Category").First(p => p.Id == productId);
         ViewBag.ProductName = product.Name;
         ViewBag.CategoryName = product.Category.Name;
         return View(pi);
     }
 }
コード例 #16
0
ファイル: CategoryController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContext())
            {
                var category = context.Category.Include("Products").First(c => c.Id == id);
                if (!category.Products.Any())
                {
                    context.DeleteObject(category);
                    context.SaveChanges();
                }

                return RedirectToAction("Index", "Home", new { area = "" });
            }
        }
コード例 #17
0
        public ActionResult Create(int id)
        {
            using (var context = new SiteContext())
            {
                ViewBag.ProductId = id;
                int max=0;
                if(context.ProductItem.Any())
                max = context.ProductItem.Max(p => p.SortOrder);
                var product = context.Product.Include("Category").First(p => p.Id == id);
                ViewBag.ProductName = product.Name;
                ViewBag.CategoryName = product.Category.Name;

                return View(new ProductItem { SortOrder = max + 1 });
            }
        } 
コード例 #18
0
ファイル: HomeController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Index(string category, string product, int? page)
        {
            using (var context = new SiteContext())
            {
                var model = new CatalogueViewModel(context, category ?? "", product, page);
                ViewBag.Page = page ?? 0;
                this.SetSeoContent(model);
                ViewBag.PageTitle = model.PageTitle;
                ViewBag.isHomePage = model.IsHomePage;

                if (model.Content != null)
                {
                    return View("Content", model);
                }

                if(model.Product!=null)
                {
                    return View("Product", model);
                }

                return View(model);
            }
        }
コード例 #19
0
        public ActionResult Create(FormCollection collection, List<HttpPostedFileBase> mainImage, List<HttpPostedFileBase> previewImage)
        {
            try
            {
                using (var context = new SiteContext())
                {
                    int imagesCount = previewImage.Count(file => file != null);


                    for (int i = 0; i < imagesCount; i++)
                    {
                        SecretImage si = new SecretImage();

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", previewImage[i].FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        previewImage[i].SaveAs(filePath);
                        si.PreviewImageSource = fileName;

                        fileName = IOHelper.GetUniqueFileName("~/Content/Images", mainImage[i].FileName);
                        filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        mainImage[i].SaveAs(filePath);
                        si.ImageSource = fileName;

                        context.AddToSecretImage(si);
                        context.SaveChanges();
                    }
                    return RedirectToAction("SiteContent", "Home", new { id = "secretlink", area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
コード例 #20
0
ファイル: ProductController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContext())
            {
                var product = context.Product.Include("Category").Include("ProductItems").First(c => c.Id == id);
                var categoryName = product.Category.Name;

                while (product.ProductItems.Any())
                {
                    var productItem = product.ProductItems.First();
                    ImageHelper.DeleteImage(productItem.ImageSource);
                    context.DeleteObject(productItem);
                }
                ImageHelper.DeleteImage(product.ImageSource);

                context.DeleteObject(product);
                context.SaveChanges();
                return RedirectToAction("Index", "Home", new { area = "", category = categoryName });
            }
        }
コード例 #21
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContext())
            {
                var pi = context.ProductItem.Include("Product").First(p => p.Id == id);
                var productId = pi.Product.Id;
                var product = context.Product.Include("Category").First(p => p.Id == productId);

                ImageHelper.DeleteImage(pi.ImageSource);
                context.DeleteObject(pi);
                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { area = "", category = product.Category.Name, product = product.Name });
            }
        }