Exemple #1
0
        public async Task <IActionResult> DeleteTarget(string id)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(id) || !Guid.TryParse(id, out _))
                {
                    return(RedirectToAction("index"));
                }

                await _targetService.DeleteAsync(id, User);

                _logger.LogInformation("{userName} deleted TargetId {targetId}.", User.Identity.Name, id);
                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception occurred in Dashboard-DeleteTarget action.");
                return(RedirectToAction("Exception", "Error"));
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            var isAuthResult = await _targetService.CheckAuthorization(id, UserId);

            if (!isAuthResult.Success)
            {
                AddModelErrors(isAuthResult);
                return(View(nameof(Index)));
            }


            var serviceResult = await _targetService.DeleteAsync(id);

            if (!serviceResult.Success)
            {
                AddModelErrors(serviceResult);
                return(View(nameof(Index)));
            }

            return(RedirectToAction(nameof(Index)));
        }