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