public async Task <IActionResult> Update([FromBody] PersonVm data)
        {
            return(await ServiceInvoker.AsyncOk(async() =>
            {
                if (!data.Id.HasValue)
                {
                    var newItem = Mapper.Map <Person>(data);

                    newItem = await _personRepository.SaveAsync(newItem);

                    return Mapper.Map <PersonVm>(newItem);
                }

                var existingItem =
                    await _personRepository.GetOneAsync(data.Id.Value);

                if (existingItem == null)
                {
                    throw new NotFoundException(nameof(Person), data.Id.Value);
                }

                existingItem = Mapper.Map(data, existingItem);

                existingItem = await _personRepository.SaveAsync(existingItem);

                return Mapper.Map <PersonVm>(existingItem);
            }));
        }
        public async Task <IActionResult> Search([FromQuery] string searchParams = "")
        {
            return(await ServiceInvoker.AsyncOk(async() =>
            {
                var people = await _personRepository.Search(searchParams);

                return people.Select(x => Mapper.Map <PersonVm>(x));
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Login([FromBody] LoginVm parameters)
        {
            return(await ServiceInvoker.AsyncOk(async() =>
            {
                var user = await _securityService.Login(parameters.Email, parameters.Password);

                if (user != null)
                {
                    var result = new LoginResultVm();

                    var tokenRequest = await BuildTokenRequest(user);

                    result.CurrentUser = Mapper.Map <UserVm>(user);
                    result.AuthToken = tokenRequest.Token;

                    return result;
                }

                throw new ApiException <string>("Invalid Credentials");
            }));
        }
Exemplo n.º 4
0
 public async Task <IActionResult> Register([FromBody] RegistrationVm parameters)
 {
     return(await ServiceInvoker.AsyncOk(async() => await _securityService.Register(parameters)));
 }
 public async Task <IActionResult> SecurityTest()
 {
     return(await ServiceInvoker.AsyncOk(() => Task.FromResult(HttpContext.User.GetUserInformation())));
 }
 public async Task <IActionResult> V2Method()
 {
     return(await ServiceInvoker.AsyncOk(() => Task.FromResult(true)));
 }
 public async Task <IActionResult> SecurityTest()
 {
     return(await ServiceInvoker.AsyncOk(() => _currentUserService.GetUserInformation()));
 }