public IActionResult GetById(int id)
        {
            Company company = _companiesRepository.GetCompanyById(id);

            if (company != null)
            {
                CompanyDto companyDto = Mapper.Map <CompanyDto>(company);
                return(Ok(companyDto));
            }

            return(NotFound());
        }
        [Route("oauth-callback")] // Entry Point
        public async Task <IActionResult> OAuthCallback(string code, string exchangeCodeUrl, string providerName)
        {
            var url = $"{exchangeCodeUrl}/internal/marketing/company?code={code}";

            try {
                using (var httpClient = _httpClientFactory.CreateClient()) {
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", InternalToken);
                    var response = await httpClient.GetAsync(url);

                    response.EnsureSuccessStatusCode();
                    var responseMessage = await response.Content.ReadAsStringAsync();

                    var radarioHost = JsonConvert.DeserializeObject <RadarioHost>(responseMessage);
                    var host        = await _hostRepo.GetCompanyById(radarioHost.Id);

                    if (host != null)
                    {
                        return(Redirect($"/{host.PublicGuid:D}"));
                    }
                }
            } catch (Exception e) {
                _logger.LogError(e, "OAuth exception");
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id)
        {
            ViewBag.CompanyId = id;
            var company = await _companiesRep.GetCompanyById(id);

            return(View(Mapper.Map <AddEditCompanyViewModel>(company)));
        }
Beispiel #4
0
        public async Task <IActionResult> Add(AddEditEmployeeViewModel model, int companyId)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.CompanyId     = companyId;
                ViewBag.IdNumberError = ModelState[nameof(model.IdNumber)]?.Errors[0].ErrorMessage;

                return(View(model));
            }

            if (await _companiesRep.GetCompanyById(companyId) != null)
            {
                await _employeesRep.AddEmployee(model, companyId);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
 public async Task <Company> ExecuteAsync(int idCompany)
 {
     return(await _companiesRepository.GetCompanyById(idCompany));
 }