public override async Task <ActionResult <UserDto> > Handle(AuthenticateUserCommand command)
        {
            var user = await _workContext.GetWorkingUser();

            if (user == null)
            {
                return(Error());
            }

            var userDto = new UserDto();

            _mapper.Map(user, userDto);

            return(Ok(userDto));
        }
Esempio n. 2
0
        public override async Task <ActionResult <ProfileDto> > Handle(GetProfileCommand command)
        {
            var workingUser = await _workContext.GetWorkingUser();

            if (workingUser == null)
            {
                return(Error());
            }

            var ordersDtoResult = await _listOrdersQueryHandler.Handle(new ListOrdersCommand(workingUser.Id));

            if (ordersDtoResult.Failure)
            {
                return(Error(ordersDtoResult.ErrorMessages));
            }

            var profileDto = new ProfileDto();
            var ordersDto  = ordersDtoResult.Object;

            profileDto.Orders = ordersDto;

            return(Ok(profileDto));
        }
Esempio n. 3
0
        public override async Task <ActionResult <UserDto> > Handle(SaveUserCommand command)
        {
            var categoryDtoResult = await _getCategoryByUrlQueryHandler.Handle(new GetCategoryByUrlCommand(command.RouteUrl, _workContext.WorkingLanguageId));

            if (categoryDtoResult.Failure)
            {
                return(Error(categoryDtoResult.ErrorMessages));
            }

            var categoryDto  = categoryDtoResult.Object;
            var detailErrors = categoryDto.Fieldsets.MapToFields(command.User).ValidateFieldsets();

            if (!detailErrors.IsNullOrEmpty())
            {
                return(Error(detailErrors));
            }

            var workingUser = await _workContext.GetWorkingUser();

            if (workingUser == null)
            {
                return(Error());
            }

            var user = _mapper.Map(command.User, workingUser);

            user.UserName = user.Email;

            var userUpdateResult = await _userManager.UpdateAsync(user);

            if (!userUpdateResult.Succeeded)
            {
                return(Error(userUpdateResult.Errors.Select(o => o.Description).ToHeaderErrors()));
            }

            return(Ok(new UserDto()));
        }