public Entryvm AddEntry(Entryvm entry) { if (entry.Date == null) { entry.Date = DateTime.Now; } var user = m.User.SingleOrDefault(x => x.Name == entry.UserName); foreach (var item in m.Archives) { if (entry.Date.Month > item.DateAdded.Month) { m.Archives.Add(new Archive()); } } entry.User = user; var archive = m.Archives.FirstOrDefault(x => x.DateAdded.Month == entry.Date.Month); entry.Archive = archive; var adddeditem = m.Entries.Add(Mapper.Map <Entryvm, Entry>(entry)); m.SaveChanges(); return((adddeditem == null) ? null : Mapper.Map <Entry, Entryvm>(adddeditem)); }
public ActionResult Create(Entryvm entry) { if (!ModelState.IsValid) { return(View(entry)); } var addedItem = m.AddEntry(entry); if (addedItem == null) { return(View(entry)); } else { return(RedirectToAction("All", "Diary", new { id = addedItem.Archive.Id })); } }
public ActionResult Create(Entryvm newItem) { if (!ModelState.IsValid) { return(View(newItem)); } var addedItem = em.AddEntry(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("Index")); } }
public Entryvm EditEntry(Entryvm entry) { var user = m.User.SingleOrDefault(x => x.Name == entry.UserName); var archive = m.Archives.SingleOrDefault(x => x.DateAdded.Month == entry.DateAdded.Month); var o = m.Entries.Find(entry.Id); o.Archive = archive; o.User = user; if (o == null) { return(null); } else { m.Entry(o).CurrentValues.SetValues(entry); m.SaveChanges(); } return(Mapper.Map <Entry, Entryvm>(o)); }
public ActionResult Edit(int?id, Entryvm entry) { if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = entry.Id })); } if (id.GetValueOrDefault() != entry.Id) { return(RedirectToAction("Home/Index")); } var edited = m.EditEntry(entry); if (edited == null) { return(RedirectToAction("edit", new { id = entry.Id })); } else { return(RedirectToAction("All")); } }