コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }