예제 #1
0
        public ServiceSingleResult <bool> DeleteReport(long reportId, string userId)
        {
            var result         = new ServiceSingleResult <bool>();
            var reportToDelete = GetReportById(reportId);

            if (reportToDelete != null)
            {
                //check security
                var projUserRef = _accessService.GetAccessByReport(reportToDelete, userId);
                if (projUserRef == null ||
                    !Inspector.CanUserDeleteReport(projUserRef, reportToDelete, userId))
                {
                    result.HandleError(ErrorMessagesDict.AccessDenied);
                    return(result);
                }

                _context.Reports.Remove(reportToDelete);
                try
                {
                    _context.SaveChanges();
                    result.TargetObject = true;
                }
                catch (Exception exc)
                {
                    result.HandleError(exc.Message);
                }
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NotFoundResource);
            return(result);
        }