Example #1
0
        public MultiCardUser CreateNewUser(MultiCardUser user)
        {
            try
            {
                user.UserId    = new Guid();
                user.CreatedAt = DateTime.Now;
                user.UpdatedAt = DateTime.Now;

                _context.MultiCardUsers.Add(user);
                var res = _context.SaveChanges();

                if (res > 0)
                {
                    return(user);
                }
                else
                {
                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                //TODO: Need to implement exception here
                throw;
            }
        }
        public IActionResult Authenticate([FromBody] MultiCardUser userParam)
        {
            var user = _userService.Authenticate(userParam.Username, userParam.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }
 public IActionResult CreateNewUser([FromBody] MultiCardUser userParam)
 {
     try
     {
         if (userParam == null)
         {
             return(BadRequest("Owner object is null"));
         }
         _userService.CreateNewUser(userParam);
         return(CreatedAtRoute("OwnerById", new { id = userParam.UserId }, userParam));
     }
     catch (Exception ex)
     {
         //_logger.LogError($"Something went wrong inside the CreateNewUser action: {ex}");
         return(StatusCode(500, ex.Message));
     }
 }
        public IActionResult GetUserById([FromBody] MultiCardUser userParam)
        {
            var user = _userService.GetUserById(userParam.UserId);

            if (user == null)
            {
                return(NotFound(new { message = "User not found" }));
            }

            // only allow admins to access other user records
            if (userParam.UserId == user.UserId || User.IsInRole(Roles.Admin))
            {
                return(Forbid());
            }

            return(Ok(user));
        }