public JsonResult AddClient(Client client) { if (ModelState.IsValid) { clientPortalInfo.Clients.Add(client); clientPortalInfo.SaveChanges(); // Grab the client after insert var clientToLogin = clientPortalInfo.Clients.FirstOrDefault(clientInstance => clientInstance.UserName == client.UserName && clientInstance.Password == client.Password); return Json(new { Success = true, UserID = clientToLogin.ID }, JsonRequestBehavior.AllowGet); } return Json(new { Success = false }, JsonRequestBehavior.AllowGet); }
public JsonResult UpdateClient(Client client) { if (ModelState.IsValid) { var clientToUpdate = clientPortalInfo.Clients.FirstOrDefault(clientInstance => clientInstance.ID == client.ID); if (clientToUpdate != null) { clientToUpdate = client; clientPortalInfo.SaveChanges(); return Json(new { Success = true }, JsonRequestBehavior.AllowGet); } } return Json(new { Success = false }, JsonRequestBehavior.AllowGet); }