Exemple #1
0
 public ActionResult Delete(int id)
 {
     using (var context = new SiteContainer())
     {
         Article article = context.Article.First(a => a.Id == id);
         context.DeleteObject(article);
         context.SaveChanges();
     }
     return RedirectToAction("Index", "Home", new { Area = "", id = "" });
 }
 public ActionResult Edit(ProductAttribute model, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var productAttribute = context.ProductAttribute.First(pa => pa.Id == model.Id);
         TryUpdateModel(productAttribute, new[] { "Title" });
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Exemple #3
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new SiteContainer())
     {
         var content = context.Content.First(c => c.Id == id);
         TryUpdateModel(content, new[] {"Title"});
         content.Text = HttpUtility.HtmlDecode(form["Text"]);
         context.SaveChanges();
         return RedirectToAction("Index", "Catalogue", new {Area = "", id = ""});
     }
 }
 public ActionResult Create(ProductAttribute model)
 {
     using (var context = new SiteContainer())
     {
         var pa = new ProductAttribute();
         TryUpdateModel(pa, new[] { "Title" });
         context.AddToProductAttribute(pa);
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Exemple #5
0
        public ActionResult Create(FormCollection form, int categoryId, HttpPostedFileBase fileUpload)
        {
            using (var context = new SiteContainer())
            {
                Product product = new Product();
                Category category = context.Category.First(c => c.Id == categoryId);
                product.Category = category;

                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Remove(attribute);
                    }
                }


                TryUpdateModel(product, new[] { "Title", "Description" });

                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", "Catalogue", new { Area = "", id = category.Name });
            }
        }
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var productAttribute = context.ProductAttribute
                    .Include("Categories")
                    .Include("Products")
                    .First(pa => pa.Id == id);

                productAttribute.Products.Clear();
                productAttribute.Categories.Clear();

                context.DeleteObject(productAttribute);
                context.SaveChanges();
            }
            return RedirectToAction("Index");
        }
Exemple #7
0
 public ActionResult Edit(int id, FormCollection form)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             Article article = context.Article.First(a => a.Id == id);
             TryUpdateModel(article, new[] { "Title", "Date" });
             article.Text = HttpUtility.HtmlDecode(form["Text"]);
             context.SaveChanges();
         }
         return RedirectToAction("Index", "Home", new { Area = "", id = "" });
     }
     catch
     {
         return View();
     }
 }
Exemple #8
0
        public void FeedbackForm(FeedbackFormModel feedbackFormModel)
        {
            using (var context = new SiteContainer())
            {
                var emails = new List<MailAddress>
                                 {
                                     new MailAddress("*****@*****.**")
                                 };

                var responseData = Helpers.MailHelper.SendTemplate(null, emails, "Форма обратной связи", null, null, true, feedbackFormModel.Name, feedbackFormModel.Email, feedbackFormModel.Text);
                var responseFeedback = new Feedback
                                           {
                                               Email = feedbackFormModel.Email,
                                               ErrorMessage = responseData.ErrorMessage,
                                               Text = feedbackFormModel.Text,
                                               Title = feedbackFormModel.Name,
                                               Sent = responseData.EmailSent
                                           };

                context.AddToFeedback(responseFeedback);
                context.SaveChanges();
            }
        }
        public ActionResult Create(FormCollection form)
        {
            using (var context = new SiteContainer())
            {
                var category = new Category();


                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }

                TryUpdateModel(category, new[] { 
                    "Name", 
                    "Title", 
                    "SortOrder", 
                    "SeoDescription", 
                    "SeoKeywords" });

                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }
Exemple #10
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var product = context.Product.Include("Category").First(p => p.Id == id);
                var categoryId = product.Category.Id;
                var category = context.Category.First(c => c.Id == categoryId);

                if (!string.IsNullOrEmpty(product.ImageSource))
                {
                    IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                    IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource);
                }
                product.ProductAttributes.Clear();
                context.DeleteObject(product);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }
Exemple #11
0
        public ActionResult Delete(int id)
        {
            using (var context = new SiteContainer())
            {
                var category = context.Category.Include("Products").First(c => c.Id == id);
                while (category.Products.Any())
                {
                    var product = category.Products.First();
                    if (!string.IsNullOrEmpty(product.ImageSource))
                    {
                        IOHelper.DeleteFile("~/Content/Images", product.ImageSource);
                        IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource);
                        product.ProductAttributes.Clear();
                        context.DeleteObject(product);
                    }
                }
                context.SaveChanges();

                category.ProductAttributes.Load();
                category.ProductAttributes.Clear();
                context.DeleteObject(category);
                context.SaveChanges();
            }
            return RedirectToAction("Index", "Home", new { Area = "", id = "" });
        }