示例#1
0
        public async Task <DeleteReportResponse> Execute(int request)
        {
            var idSpecification = new IdSpecification(request);

            var reportQueryable = _reportsRepository.Get(idSpecification);

            var report = await _reportsRepository.SingleOrDefaultAsync(reportQueryable);

            if (report == null)
            {
                return(new DeleteReportResponse
                {
                    Succedeed = false
                });
            }

            _reportsRepository.RemoveEntity(report);

            await _reportsRepository.SaveChangesAsync();

            return(new DeleteReportResponse
            {
                Succedeed = true
            });
        }
示例#2
0
        public async Task <UpdateReportResponse> Execute(UpdateReportRequest request)
        {
            var validationErrors = _validationService.Validate(request.Model);

            if (validationErrors.Any())
            {
                return(new UpdateReportResponse
                {
                    Data = new Either <Dtos.ReportDto, IEnumerable <KeyValuePair <string, string> > >(validationErrors)
                });
            }

            var idSpecification = new IdSpecification(request.ReportId);

            var reportQueryable = _reportRepository.Get(idSpecification);

            var report = await _reportRepository.SingleOrDefaultAsync(reportQueryable);

            if (report == null)
            {
                var message         = string.Format(DomainMessages.ReportNull, request.ReportId);
                var reportNullError = new KeyValuePair <string, string>(nameof(request.ReportId), message);

                return(new UpdateReportResponse
                {
                    Data = new Either <Dtos.ReportDto, IEnumerable <KeyValuePair <string, string> > >(new List <KeyValuePair <string, string> > {
                        reportNullError
                    })
                });
            }

            report.ReportTypeId    = (int)request.Model.ReportTypeId;
            report.AverageSpeed    = request.Model.AverageSpeed;
            report.InstructedSpeed = request.Model.InstructedSpeed;

            await _reportRepository.SaveChangesAsync();

            return(new UpdateReportResponse
            {
                Data = new Either <Dtos.ReportDto, IEnumerable <KeyValuePair <string, string> > >(new Dtos.ReportDto
                {
                    ReportId = report.ReportId,
                    AverageSpeed = report.AverageSpeed,
                    InstructedSpeed = report.InstructedSpeed,
                    ReportTypeId = report.ReportTypeId
                })
            });
        }
        public async Task <ReadReportResponse> Execute(int request)
        {
            var specification = new IdSpecification(request);

            var reportQuery = _reportRepository.Get(specification);

            var projection = reportQuery.Select(ReportsSelectors.ReportSelector);

            var reportDto = await _reportRepository.SingleOrDefaultAsync(projection);

            if (reportDto == null)
            {
                return(new ReadReportResponse
                {
                    Report = new Either <Dtos.ReportDto, UseCaseResponse>(UseCaseResponse.Null())
                });
            }

            return(new ReadReportResponse
            {
                Report = new Either <Dtos.ReportDto, UseCaseResponse>(reportDto)
            });
        }
 public void IdSpecification_IsSatisfiedBy_Success()
 {
     var spec = new IdSpecification<int, Product>(10);
     Assert.True(spec.IsSatisfiedBy(_product));
 }
示例#5
0
        public void IdSpecification_IsSatisfiedBy_Success()
        {
            var spec = new IdSpecification <int, Product>(10);

            Assert.True(spec.IsSatisfiedBy(_product));
        }