Пример #1
0
        public ServiceSingleResult <bool> UpdateReport(Report report, string userId)
        {
            var result = new ServiceSingleResult <bool>();

            if (report != null)
            {
                var reportToUpdate = GetReportById(report.Id);

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

                    _context.Entry(reportToUpdate).CurrentValues.SetValues(report);
                    try
                    {
                        _context.SaveChanges();
                        result.TargetObject = true;
                    }
                    catch (Exception exc)
                    {
                        result.HandleError(exc.Message);
                    }
                    return(result);
                }

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

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