Ejemplo n.º 1
0
 public ActionResult EditEntry(Guid id)
 {
     var entry = _entryService.GetEntry(id);
     var model = new EntryEditModel
     {
         ID = entry.ID,
         EntryBody = entry.EntryBody,
         Title = entry.Title
     };
     var tags = entry.Tags.Select(item => item.Name).ToList();
     model.Tags = String.Join(", ", tags);
     return View("~/Views/Entry/Edit.cshtml", model);
 }
Ejemplo n.º 2
0
 public ActionResult EditEntry(EntryEditModel entry)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Entry entryToUpdate = _entryService.GetEntry(entry.ID);
             entryToUpdate.Title = entry.Title;
             entryToUpdate.EntryBody = entry.EntryBody;
             if (entry.Tags != null)
             {
                 IEnumerable<string> tags = TagEditor.SplitTags(entry.Tags).Distinct();
                 entryToUpdate.Tags = new List<Tag>();
                 foreach (var tag in tags)
                 {
                     var tmp = _tagService.GetTag(tag.Trim());
                     if (tmp == null)
                     {
                         tmp = new Tag
                         {
                             Name = tag.Trim()
                         };
                         _tagService.CreateTag(tmp);
                     }
                     entryToUpdate.Tags.Add(tmp);
                 }
             }
             else
             {
                 entryToUpdate.Tags = null;
             }
             _entryService.UpdateEntry(entryToUpdate);
             return RedirectToAction("Entries", "Administrator", new { id = entryToUpdate.Blog.ID });
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Произошла ошибка. Невозможно отредактировать запись.");
     }
     return View("~/Views/Entry/Edit.cshtml");
 }
Ejemplo n.º 3
0
 public ActionResult Edit(EntryEditModel entry)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Entry entryToUpdate = _entryService.GetEntry(entry.ID);
             entryToUpdate.Title = entry.Title;
             entryToUpdate.EntryBody = entry.EntryBody;
             if (entry.Tags != null)
             {
                 IEnumerable<string> tags = TagEditor.SplitTags(entry.Tags).Distinct();
                 entryToUpdate.Tags = new List<Tag>();
                 foreach (var tag in tags)
                 {
                     var tmp = _tagService.GetTag(tag.Trim());
                     if (tmp == null)
                     {
                         tmp = new Tag
                         {
                             Name = tag.Trim()
                         };
                         _tagService.CreateTag(tmp);
                     }
                     entryToUpdate.Tags.Add(tmp);
                 }
             }
             else
             {
                 entryToUpdate.Tags = null;
             }
             _entryService.UpdateEntry(entryToUpdate);
             return RedirectToAction("Entries", "Blog", new { id = entryToUpdate.Blog.ID });
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Error! Unable to edit entry.");
     }
     return View("Edit");
 }