Exemple #1
0
        public bool PostCharacters([FromBody] Characters characters)
        {
            try
            {
                if (!_context.Classes.Any(c => c.ClassName == characters.ClassIdFkNavigation.ClassName))
                {
                    _context.Classes.Add(characters.ClassIdFkNavigation);
                    _context.SaveChanges();
                }

                Classes existing = _context.Classes.FirstOrDefault(c => c.ClassName == characters.ClassIdFkNavigation.ClassName);

                characters.ClassIdFk = existing.ClassId;

                _context.Characters.Add(characters);
                _context.SaveChanges();

                characters = _context.Characters.FirstOrDefault(c => c.FullName == characters.FullName);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public int Register([FromBody] Users userInfo)
        {
            try
            {
                if (!UsernameExists(userInfo.Username))
                {
                    _context.Users.Add(userInfo);
                    _context.SaveChanges();
                    userInfo = _context.Users.FirstOrDefault(u => u.Username == userInfo.Username);

                    return(userInfo.UserId);
                }
                else
                {
                    //using -1 as code for "username taken"
                    return(-1);
                }
            }
            catch
            {
                //using 0 as code for error
                return(0);
            }
        }