public ActionResult Create(UserViewModel model) { try { using (Domain.ZanyContext context = new Domain.ZanyContext()) { var newEntity = context.Users.Create(); newEntity.Email = model.Email; newEntity.FacebookHandle = model.FacebookHandle; newEntity.FirstName = model.FirstName; newEntity.LastName = model.LastName; newEntity.TwitterHandle = model.TwitterHandle; newEntity.UserName = model.Username; newEntity.WebUrl = model.WebUrl; context.Users.Add(newEntity); context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Delete(int id, FormCollection collection) { try { UserViewModel model = null; using (Domain.ZanyContext context = new Domain.ZanyContext()) { var sourceObj = context.Users .Where(u => u.UserId == id) .FirstOrDefault(); if (sourceObj != null) { context.Users.Remove(sourceObj); context.SaveChanges(); } } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(UserViewModel model) { try { using (Domain.ZanyContext context = new Domain.ZanyContext()) { var toUpdate = context.Users .Where(u => u.UserId == model.UserId) .FirstOrDefault(); if (toUpdate != null) { toUpdate.Email = model.Email; toUpdate.FacebookHandle = model.FacebookHandle; toUpdate.FirstName = model.FirstName; toUpdate.LastName = model.LastName; toUpdate.TwitterHandle = model.TwitterHandle; toUpdate.UserName = model.Username; toUpdate.WebUrl = model.WebUrl; context.SaveChanges(); } } return RedirectToAction("Index"); } catch { return View(); } }