Example #1
0
        public IActionResult Delete(int id)
        {
            var client = _clientRepo.GetById(id);

            _clientRepo.Delete(client);

            return(RedirectToAction("List"));
        }
Example #2
0
        public async Task <ClientDto> GetById(int userId, int clientId)
        {
            // TODO: [TESTS] (ClientService.GetById) Add tests
            var builder = new ServiceMetricBuilder(nameof(ClientService), nameof(GetById))
                          .WithCategory(MetricCategory.Client, MetricSubCategory.GetById)
                          .WithCustomInt1(userId)
                          .WithCustomInt2(clientId);

            try
            {
                using (builder.WithTiming())
                {
                    ClientEntity dbClient;
                    using (builder.WithCustomTiming2())
                    {
                        builder.IncrementQueryCount();
                        dbClient = await _clientRepo.GetById(clientId);

                        builder.CountResult(dbClient);
                    }

                    if (dbClient == null)
                    {
                        return(null);
                    }

                    // ReSharper disable once InvertIf
                    if (dbClient.UserId != userId)
                    {
                        // TODO: [HANDLE] (ClientService.GetById) Handle this better
                        _logger.Warning("Requested client '{cname}' ({cid}) does not belong to user ({uid})",
                                        dbClient.ClientName,
                                        dbClient.ClientId,
                                        userId
                                        );

                        return(null);
                    }

                    return(ClientDto.FromEntity(dbClient));
                }
            }
            catch (Exception ex)
            {
                _logger.LogUnexpectedException(ex);
                builder.WithException(ex);
                return(null);
            }
            finally
            {
                await _metrics.SubmitPointAsync(builder.Build());
            }
        }
Example #3
0
        // GET: ClientController/Edit/5
        public IActionResult  Edit(int id)
        {
            if (id < 0)
            {
                return(NotFound());
            }
            var _client = _clientRepo.GetById(id);

            if (_client == null)
            {
                return(NotFound());
            }
            EditClientViewModel client = _mapper.Map <EditClientViewModel>(_client);

            return(PartialView("_Edit", client));
        }
        public IActionResult Details(int id)
        {
            if (id < 0)
            {
                return(NotFound());
            }
            var _server = _serverRepo.GetById(id);

            if (_server == null)
            {
                return(NotFound());
            }
            var _client = _clientRepo.GetById(_server.ClientId);
            ViewServerViewModel server = _mapper.Map <ViewServerViewModel>(_server);

            server.ClientName = _client.Name;

            return(PartialView("_Details", server));
        }
Example #5
0
        // GET: VpnController/Details/5
        public IActionResult Details(int id)
        {
            if (id < 0)
            {
                return(NotFound());
            }
            var _vpn = _vpnRepo.GetById(id);

            if (_vpn == null)
            {
                return(NotFound());
            }
            var _client = _clientRepo.GetById(_vpn.ClientId);

            ViewVpnViewModel vpn = _mapper.Map <ViewVpnViewModel>(_vpn);

            vpn.ClientName = _client.Name;

            return(PartialView("_Details", vpn));
        }
Example #6
0
 public Client GetByID(int id)
 {
     return(ClientRepo.GetById(id));
 }