예제 #1
0
        public async Task <IActionResult> DeleteReport(int id, [Bind("Id, Title")] DeleteReportViewModel reportToDelete)
        {
            try
            {
                if (id != reportToDelete.Id)
                {
                    return(NotFound());
                }

                var oldReport = _reportRepository.GetReportById(id);
                if (oldReport != null)
                {
                    var user = await _userManager.GetUserAsync(User);

                    if (oldReport.Reporter.Id == user.Id)
                    {
                        if (ModelState.IsValid)
                        {
                            _reportRepository.DeleteReport(oldReport);
                            return(RedirectToAction("ViewReports"));
                        }
                        else
                        {
                            return(View(reportToDelete));
                        }
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(View());
            }
        }
예제 #2
0
        public async Task <IActionResult> DeleteReport(int id)
        {
            try
            {
                var report = _reportRepository.GetReportById(id);

                if (report != null)
                {
                    var user = await _userManager.GetUserAsync(User);

                    if (report.Reporter.Id == user.Id)
                    {
                        DeleteReportViewModel model = new DeleteReportViewModel()
                        {
                            Title = _reportRepository.GetReportById(id).Title,
                            Id    = report.Id
                        };

                        return(View(model));
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(View("Error"));
            }
        }