Exemple #1
0
        public IActionResult Put(int id, [FromBody] DailyCheck DailyCheck)
        {
            // error to handle if the user input the correct info in order to use the api
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != DailyCheck.DailyCheckId)
            {
                return(BadRequest());
            }
            _context.DailyCheck.Update(DailyCheck);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
Exemple #2
0
        public IActionResult Delete(int id)
        {
            Goals Goals = _context.Goals.Single(g => g.GoalsId == id);

            if (User == null)
            {
                return(NotFound());
            }
            _context.Goals.Remove(Goals);
            _context.SaveChanges();
            return(Ok(User));
        }
Exemple #3
0
        public async Task <IActionResult> Create(string username, string password, string firstname, string lastname)
        {
            // // Check simplistic username and password validation rules

            bool isValid = IsValidUserAndPasswordCombination(username, password);

            if (isValid)
            {
                // Does the user already exist?
                User user = _context.User.SingleOrDefault(u => u.Email == username);

                if (user != null)
                {
                    // Found the user, verify credentials
                    var result = await _signInManager.PasswordSignInAsync(user, password, false, lockoutOnFailure : false);

                    // Password is correct, generate token and return it
                    if (result.Succeeded)
                    {
                        return(new ObjectResult(GenerateToken(user.UserName)));
                    }
                }
                else
                {
                    var userstore = new UserStore <User>(_context);

                    // User does not exist, create one
                    user = new User {
                        FirstName          = firstname,
                        LastName           = lastname,
                        UserName           = username,
                        NormalizedUserName = username.ToUpper(),
                        Email           = username,
                        NormalizedEmail = username.ToUpper(),
                        EmailConfirmed  = true,
                        LockoutEnabled  = false,
                        SecurityStamp   = Guid.NewGuid().ToString("D")
                    };
                    var passwordHash = new PasswordHasher <User>();
                    user.PasswordHash = passwordHash.HashPassword(user, password);
                    await userstore.CreateAsync(user);

                    // await userstore.AddToRoleAsync(user);
                    _context.SaveChanges();
                    return(new ObjectResult(GenerateToken(user.UserName)));
                }
            }
            return(BadRequest());
        }