Пример #1
0
        public async Task <IHttpActionResult> CreateUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (string.IsNullOrWhiteSpace(user.NickName) || string.IsNullOrWhiteSpace(user.Email) || string.IsNullOrWhiteSpace(user.Password))
            {
                return(BadRequest());
            }

            try
            {
                await db.CreateAUser(user);
            }
            catch
            {
                return(BadRequest());
            }

            int?id = await db.Users
                     .Where((u) => u.NickName == user.NickName)
                     .Select((u) => u.UserID)
                     .SingleOrDefaultAsync();

            return(Json <int?>(id));
        }