public IActionResult GetUserById(FindByIdRequest req)
        {
            var res = _userService.FindById(req);

            if (res.Errors is null || res.Errors.Count > 0)
            {
                return(BadRequest(res));
            }

            return(Ok(res));
        }
        public IActionResult GetRoleById([FromBody] FindByIdRequest req)
        {
            FindByIdResponse <RoleDTO> res = _roleService.FindById(req);

            if (!res.Success)
            {
                return(NotFound(res));
            }

            return(Ok(res));
        }
Esempio n. 3
0
        public async Task <Quote> FindById(Guid quoteId, bool onlyApproved = true, bool enrichWithUser = false)
        {
            var data = new FindByIdRequest
            {
                QuoteId        = quoteId,
                OnlyApproved   = onlyApproved,
                EnrichWithUser = enrichWithUser
            };
            var msg = await _natsService.RequestAsync(data);

            return(msg.GetData <Quote>());
        }
Esempio n. 4
0
        public FindByIdResponse <UserDTO> FindById(FindByIdRequest req)
        {
            var res  = new FindByIdResponse <UserDTO>();
            var user = _userRepository.FindById(req.Id);

            if (user == null)
            {
                return((FindByIdResponse <UserDTO>)
                       res.ReturnErrorResponseWith(MagicStrings.Users.Error.NotFound));
            }

            res.EntityDTO = _mapper.Map <User, UserDTO>(user);
            res.Success   = true;
            return(res);
        }
Esempio n. 5
0
        public FindByIdResponse <RoleDTO> FindById(FindByIdRequest req)
        {
            var res  = new FindByIdResponse <RoleDTO>();
            var role = _roleRepository.FindById(req.Id);

            if (role == null)
            {
                res.Success = false;
                res.Errors.Add("Role not found");
                return(res);
            }

            res.Success   = true;
            res.EntityDTO = _mapper.Map <Role, RoleDTO>(role);
            return(res);
        }
        /// <summary>
        /// Find User by Id and return View of User
        /// </summary>
        /// <param name="request">Instance of FindByIdRequest</param>
        /// <returns>Instance of FindByIdResponse</returns>
        public FindByIdResponse FindById(FindByIdRequest request)
        {
            FindByIdResponse response = new FindByIdResponse();

            try
            {
                AspNetUser result = UserManager.FindById(request.UserId.ToString());
                response.UserView = result.ConvertToUserView();
                response.Success  = true;
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
            }

            return(response);
        }
        public FindByIdResponse <TById> FindById(FindByIdRequest req)
        {
            var res = new FindByIdResponse <TById>();

            var user = _repository.FindById(req.Id);

            if (res is null)
            {
                res.Errors.Add($"User with {req.Id} doesnt exist");
                res.Success = false;
                return(res);
            }

            res.Success = true;
            //map entity to dto!
            //res.Entity = user;

            return(res);
        }
Esempio n. 8
0
 public virtual Task <FindByIdResponse> GetAsync(FindByIdRequest request) =>
 Client.SendAsync <FindByIdResponse>(request);
Esempio n. 9
0
 public Task <Quote> OnFindById(FindByIdRequest req)
 {
     return(_quoteService.FindById(req.QuoteId, req.OnlyApproved, req.EnrichWithUser));
 }
        /// <summary>
        /// Find User by Id and return View of User Async version
        /// </summary>
        /// <param name="request">Instance of FindByIdRequest</param>
        /// <returns>Instance of FindByIdResponse</returns>
        public async Task<FindByIdResponse> FindByIdAsync(FindByIdRequest request)
        {
            FindByIdResponse response = new FindByIdResponse();

            try
            {

                AspNetUser result = await UserManager.FindByIdAsync(request.UserId.ToString());
                response.UserView = result.ConvertToUserView();
                response.Success = true;
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
            }

            return response;
        }