public IActionResult GetMyBusinessCard()
        {
            var userId       = _userManager.GetUserId(User);
            var businessCard = _businessCardRepository.GetBusinessCard(userId);

            if (businessCard == null)
            {
                _logger.LogInformation("Business card wasn't found.");
                return(NotFound("Business card not found!"));
            }

            var businessCardDto = Mapper.Map <BusinessCardDto>(businessCard);

            return(Ok(businessCardDto));
        }
示例#2
0
        public IActionResult ApproveOrRejectEmployee(int id, [FromBody] EmployeeForUpdateDto employeeForUpdateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var businessCard = _businessCardRepository.GetBusinessCard(employeeForUpdateDto.BusinessCardId);

            if (businessCard == null)
            {
                return(NotFound($"Business card with id {employeeForUpdateDto.BusinessCardId} was not found!"));
            }
            var company = _companyRepository.GetCompany(id);

            if (businessCard.User.Company == company && businessCard.User.EmployeeStatus == EmployeeStatus.NotApproved)
            {
                businessCard.User.EmployeeStatus = employeeForUpdateDto.Status;
                _managerRepository.UpdateEmployee(businessCard.User);
                if (_managerRepository.Save())
                {
                    return(NoContent());
                }
                else
                {
                    _logger.LogError($"Failed to update employee with user id {businessCard.User.Id} for company {company.Id}.");
                    return(StatusCode(500, "A problem happened while handling your request."));
                }
            }
            return(BadRequest());
        }
示例#3
0
        public async Task <IActionResult> WhoAmI()
        {
            var user = await _userManager.GetUserAsync(User);

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

            var userCompany = _companyRepository.GetUserCompany(user);

            var businessCard = _businessCardRepository.GetBusinessCard(user.Id);

            var res = new WhoAmIDto
            {
                BusinessCardId = businessCard?.Id,
                CompanyId      = userCompany?.Id,
                EmployeeStatus = user.EmployeeStatus == EmployeeStatus.NotApproved ? "Not approved" : user.EmployeeStatus.ToString()
            };

            return(Ok(res));
        }