Пример #1
0
 public ActionResult Edit(int id, Post model, FormCollection form, HttpPostedFileBase file)
 {
     try
     {
         var post = _context.Articles.First(p => p.Id == id);
         TryUpdateModel(post, new[] { "Title", "Date", "Description"});
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Пример #2
0
        public ActionResult Create(Post model, FormCollection form)
        {
            try
            {
                var post = new Article
                {
                    Title = model.Title,
                    Date = model.Date,
                    Description = model.Description
                };

                _context.Articles.Add(post);

                _context.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }