Example #1
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 #2
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 = "" });

        }