public ViewResult CreateTag()
 {
     var newTag = new Tag();
     return View("EditTag", newTag);
 }
 public ActionResult EditTag(Tag newTag)
 {
     if (ModelState.IsValid)
     {
         if (_repo.UpdateTag(newTag))
         {
             TempData["message"] = string.Format("{0} успешно сохранен", newTag.Name);
             return RedirectToAction("Tags");
         }
     }
     return View();
 }
        public bool UpdateTag(Tag tag)
        {
            using (var context = new EFDbContext())
            {
                try
                {
                    if (tag.Id == 0)
                    {
                        var newTag = tag;
                       context.Tags.Add(newTag);

                    }
                    else
                    {
                        var tagFromDb = context.Tags
                            .Include(p => p.Posts)
                            .Single(p => p.Id == tag.Id);

                        context.Entry(tagFromDb).CurrentValues.SetValues(tag);

                    }
                    context.SaveChanges();
                    return true;
                }
                catch (Exception)
                {

                    throw;
                    return false;
                }
            }
        }