public ViewResult Edit(string id) { MemeModel meme = null; Guid memeGuid; if (Guid.TryParse(id, out memeGuid)) { meme = _memeRepository.Get(memeGuid).ToModel(); } else { meme = new MemeModel { MemeID = Guid.Empty }; } return View(meme); }
public ActionResult Edit(MemeModel memeModel, string action) { switch (action) { case "save": { if (ModelState.IsValid) { if (memeModel.MemeID == Guid.Empty) { memeModel.MemeID = Guid.NewGuid(); _memeRepository.Add(memeModel.FromModel()); } else { _memeRepository.Update(memeModel.FromModel()); } } else { return View(memeModel); } break; } case "delete": { if (memeModel != null) { _memeRepository.Delete(memeModel.MemeID); } break; } default: break; } return RedirectToAction("Edit", new { id = Guid.Empty }); }
public void Add(MemeModel meme) { Memes.Add(meme); }