示例#1
0
        public JsonResult post(Users user)
        {
            /*var tb = _context.Users.ToList();*/
            var  authUser = _context.Users.Where((x) => x.Email == user.Email).FirstOrDefault();
            bool found    = false;

            /*List<string> pNotes = new List<string>();
             * foreach (var a in tb)
             * {
             *  if (user.Email == a.Email)
             *  {
             *      found = true;
             *  }
             * }*/

            if (authUser == null)
            {
                _ = _context.Users.Add(user);
                _context.SaveChanges();
                return(new JsonResult(found.ToString()));
            }
            else
            {
                found = true;
                return(new JsonResult(found.ToString()));
            }
        }
示例#2
0
        public JsonResult PutUser(int id, Users user)
        {
            user.UserId = id;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(new JsonResult("User Not Found"));
                }
                else
                {
                    throw;
                }
            }

            return(new JsonResult("User saved sucessfully"));
        }