Example #1
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();
     }
 }
Example #2
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();
     }
 }
Example #3
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=""});
            }
        }
Example #4
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 });
     }
 }
Example #5
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 = "" });
     }
 }
Example #6
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=""});
     }
 }
Example #7
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});
     }
 }
Example #8
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);
            }
        }
Example #9
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 = "" });
 }
Example #10
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 = "" });

        }
Example #11
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 });
     }
 }
Example #12
0
        public ActionResult Create(int categoryId, FormCollection form, HttpPostedFileBase fileUpload)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var category = context.Category.First(c => c.Id == categoryId);
                    var product = new Product{Category = category};
                    TryUpdateModel(product, new[] {"Title", "Discount", "DiscountText", "Price"});

                    product.Description = HttpUtility.HtmlDecode(form["Description"]);
                    if (fileUpload != null)
                    {
                        //if (!string.IsNullOrEmpty(product.ImageSource))
                        //{

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

                    context.AddToProduct(product);

                    context.SaveChanges();
                }
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #13
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase fileUpload)
        {

            using (var context = new SiteContainer())
            {
                var article = new Article { Name = "" };
                TryUpdateModel(article, new[] { "Name", "Title", "Date", "Description","PageTitle"});
                article.Text = HttpUtility.HtmlDecode(form["Text"]);
                article.OldPrice = HttpUtility.HtmlDecode(form["OldPrice"]);
                article.NewPrice = HttpUtility.HtmlDecode(form["NewPrice"]);
                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);
                    article.ImageSource = fileName;
                }
                context.AddToArticle(article);
                context.SaveChanges();
            }
            return RedirectToAction("Articles", "Home", new { area = "" });

        }
Example #14
0
        public ActionResult Delete(int id, int? page)
        {
            using (var context = new SiteContainer())
            {
                var product = context.Product.Include("Category").Include("ProductImages").First(p => p.Id == id);
                var categoryName = product.Category.Name;
                var specialCategory = product.Category.SpecialCategory;
                while (product.ProductImages.Any())
                {
                    var productImage = product.ProductImages.First();
                    ImageHelper.DeleteImage(productImage.ImageSource);
                    context.DeleteObject(productImage);
                }

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

                if (specialCategory)
                {
                    return RedirectToAction("OurWorks", "Home", new { area = "" });
                }

                return RedirectToAction("Gallery", "Home", new { area = "", id = categoryName });
            }
        }
Example #15
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();
            }
        }
Example #16
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var article = context.Article.First(a => a.Id == id);
                if (!string.IsNullOrEmpty(article.ImageSource))
                {

                    IOHelper.DeleteFile("~/Content/Images", article.ImageSource);
                    foreach (var thumbnail in SiteSettings.Thumbnails)
                    {
                        IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, article.ImageSource);
                    }
                }
                context.DeleteObject(article);
                context.SaveChanges();
                return RedirectToAction("Articles", "Home", new { area = "" });
            }
        }
Example #17
0
 public ActionResult Delete(int id, int? page)
 {
     using (var context = new SiteContainer())
     {
         var product = context.Product.First(p => p.Id == id);
         ImageHelper.DeleteImage(product.ImageSource);
         context.DeleteObject(product);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Example #18
0
 public ActionResult DeleteProductSize(int id)
 {
     using (var context = new SiteContainer())
     {
         var productSize = context.ProductSize.Include("Product").First(ps => ps.Id == id);
         var productId = productSize.Product.Id;
         context.DeleteObject(productSize);
         context.SaveChanges();
         return RedirectToAction("ProductDetails", "Home", new { area = "", id = productId });
     }
 }
Example #19
0
 public ActionResult EditProductSize(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var productSize = context.ProductSize.Include("Product").First(ps => ps.Id == id);
         TryUpdateModel(productSize, new[] { "Size" });
         context.SaveChanges();
         return RedirectToAction("ProductDetails", "Home", new { area = "", id = productSize.Product.Id });
     }
 }
Example #20
0
 public ActionResult AddProductSize(int productId, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var product = context.Product.First(c => c.Id == productId);
         var ps = new ProductSize();
         TryUpdateModel(ps, new[] { "Size" });
         product.ProductSizes.Add(ps);
         context.SaveChanges();
         return RedirectToAction("ProductDetails", "Home", new { area = "", id = productId });
     }
 }
Example #21
0
        public ActionResult DeleteProductImage(int id)
        {
            using (var context = new SiteContainer())
            {
                var productImage = context.ProductImage.Include("Product").First(pi => pi.Id == id);
                var productId = productImage.Product.Id;

                //if (productImage.Product.ImageSource == productImage.ImageSource)
                //{

                //}


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

                return RedirectToAction("ProductDetails", "Home", new { area = "", id = productId });
            }
        }
Example #22
0
        public ActionResult Order(OrderFormModel orderFormModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new SiteContainer())
                    {
                        var order = new Order
                                        {
                                            Address = orderFormModel.Address,
                                            Email = orderFormModel.Email,
                                            Name = orderFormModel.Name,
                                            Phone = orderFormModel.Phone,
                                            Size = orderFormModel.Size
                                        };


                        //var size = orderFormModel.Size.FirstOrDefault(s => s.Selected);
                        //if (size != null)
                        //{
                        //    order.Size = size.Text;
                        //}

                        context.AddToOrder(order);
                        context.SaveChanges();
                    }

                    string defaultMailAddressFrom = ConfigurationManager.AppSettings["feedbackEmailFrom"];
                    string defaultMailAddresses = ConfigurationManager.AppSettings["feedbackEmailsTo"];

                    string subject = ConfigurationManager.AppSettings["orderMailSubject"];
                    string displayName = ConfigurationManager.AppSettings["orderDisplayName"];

                    var emailFrom = new MailAddress(defaultMailAddressFrom, displayName);

                    var emailsTo = defaultMailAddresses
                        .Split(new[] { ";", " ", "," }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => new MailAddress(s))
                        .ToList();

                    var result = Helpers.MailHelper.SendOrderTemplate(emailFrom, emailsTo, subject, "OrderTemplate.htm", null, true, orderFormModel.Name, string.IsNullOrEmpty(orderFormModel.Email) ? "[не указано]" : orderFormModel.Email, orderFormModel.Phone, orderFormModel.Address,orderFormModel.Size,orderFormModel.ProductId,orderFormModel.ProductTitle);
                    if (result.EmailSent)
                        return PartialView("SuccessOrder");
                    orderFormModel.ErrorMessage = "Ошибка: " + result.ErrorMessage;
                }
                catch (Exception ex)
                {
                    orderFormModel.ErrorMessage = ex.Message;
                    if (ex.InnerException != null)
                        orderFormModel.ErrorMessage += " " + ex.InnerException.Message;
                }
            }
            return PartialView("OrderForm", orderFormModel);
        }
Example #23
0
        public ActionResult SetCoverImage(int id)
        {
            using (var context = new SiteContainer())
            {
                var productImage = context.ProductImage.Include("Product").First(pi => pi.Id == id);
                productImage.Product.ImageSource = productImage.ImageSource;
                var productId = productImage.Product.Id;
                context.SaveChanges();

                var product = context.Product.Include("Category").First(p => p.Id == productId);
                if (product.Category.SpecialCategory)
                {
                    return RedirectToAction("WorkDetails", "Home", new { area = "", id = product.Id });
                }
                return RedirectToAction("ProductDetails", "Home", new { area = "", id = productImage.Product.Id });
            }
        }
Example #24
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         var banner = context.Banner.First(b => b.Id == id);
         IOHelper.DeleteFile("~/Content/Images", banner.ImageSource);
         foreach (var thumbnail in SiteSettings.Thumbnails)
         {
             IOHelper.DeleteFile("~/ImageCache/" + thumbnail.Key, banner.ImageSource);
         }
         context.DeleteObject(banner);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }