public async Task <long> AddFailuresReport(FailureReport failureReport)
        {
            _context.Add(failureReport);
            await _context.SaveChangesAsync();

            return(failureReport.Id);
        }
        public void MapTo(List <FailureReportDto> dbData, List <FailureReport> ourModel)
        {
            if (dbData == null || dbData.Count < 1 || ourModel == null)
            {
                return;
            }

            // Loop through dtatabase results and map to our model
            foreach (var data in dbData)
            {
                var failureReport = new FailureReport()
                {
                    RecordId   = data.RecordId,
                    TestCase   = data.TestCase,
                    RgNumber   = data.RgNumber,
                    RgValue    = BuildRgValue(data.RgNumber),
                    Time       = data.Time,
                    Category   = data.Category,
                    Comment    = data.Comment,
                    Details    = BuildMessages(data.Detail),
                    TestReport = data.TestReport,
                };

                ourModel.Add(failureReport);
            }
        }
        /// <summary>
        /// Check the failure types and add them to a list.
        /// </summary>
        /// <param name="failureReport">The report contains the types.</param>
        /// <param name="itemsToAdd">Failure types to add.</param>
        /// <returns>A value indicates whether the operation is succeed.</returns>
        private bool CheckTypesAndAdd(FailureReport failureReport, ICollection <FailureItemDto> itemsToAdd)
        {
            if (failureReport == null || itemsToAdd == null)
            {
                throw new ArgumentNullException();
            }

            //get all enabled types
            var failureTypes = _typeRepo.GetAllTypes().ToList();

            if (IsDuplicateOrInvalid(itemsToAdd, failureTypes))
            {
                return(false);
            }

            failureReport.Items = itemsToAdd.Select(item => new FailureItem
            {
                Count  = item.Count,
                Detail = item.Detail,
                Report = failureReport,
                Type   = failureTypes.First(ft => ft.Id == item.TypeId)
            }).ToList();

            return(InSameCategory(failureReport));
        }
        public async Task <IHttpActionResult> Post(FailureReportCreationDto dto)
        {
            var user = await User.GetEntityAsync(_identityRepo);

            if (IsDuplicateSubmit(dto, user))
            {
                return(StatusCode(HttpStatusCode.Created));
            }

            var report = new FailureReport
            {
                Title = dto.Title,
                Time  = DateTime.UtcNow,
                State = ReportStates.Waiting,
                Items = new List <FailureItem>()
            };

            if (!CheckTypesAndAdd(report, dto.Items))
            {
                return(BadRequest("故障项不正确"));
            }

            report.Reporter = user;

            await _failureRepo.CreateAsync(report);

            return(StatusCode(HttpStatusCode.Created));
        }
        public async Task <int> CreateAsync(FailureReport report)
        {
            if (report == null)
            {
                throw new ArgumentNullException();
            }
            _dbContext.Users.Attach(report.Reporter);
            report.Items.ToList().ForEach(ft => _dbContext.FailureTypes.Attach(ft.Type));
            _dbContext.FailureReports.Add(report);
            await _dbContext.SaveChangesAsync();

            return(report.Id);
        }
Пример #6
0
        public void GivenCorrectData_WhenCreatingNewFailureRepory_ThenFailureReportIsCreated()
        {
            // given
            var description = "New localization";
            var resourceId  = 1;
            var reporterId  = 2;
            var date        = DateTime.Now;
            var status      = RepairStatusEnum.Done;

            //when
            var localization = new FailureReport(description, resourceId, reporterId, date, status);

            //then
            localization.FailureDescription.ShouldBe(description);
            localization.ResourceId.ShouldBe(resourceId);
            localization.ReporterId.ShouldBe(reporterId);
            localization.DateOfReporting.ShouldBe(date);
            localization.RepairStatus.ShouldBe(status);
        }
        public async Task SaveAsync(FailureReport report)
        {
            if (report.Feedback != null)
            {
                if (report.FeedbackId == null)
                {
                    _dbContext.Feedbacks.Add(report.Feedback);
                }
                else
                {
                    report.Feedback.Id = report.FeedbackId.Value;
                    _dbContext.Feedbacks.Attach(report.Feedback);
                    _dbContext.Entry(report.Feedback).State = EntityState.Modified;
                    await _dbContext.SaveChangesAsync();
                }
            }

            _dbContext.FailureReports.Attach(report);
            _dbContext.Entry(report).State = EntityState.Modified;

            await _dbContext.SaveChangesAsync();
        }
 public static FailureReportDto ToDto(this FailureReport report)
 {
     return(Mapper.Map <FailureReportDto>(report));
 }
 public static ReportingDto ToReportingDto(this FailureReport report)
 {
     return(Mapper.Map <ReportingDto>(report));
 }
Пример #10
0
        public async Task <long> AddFailureReport(AddFailureCommand command)
        {
            var failureReport = new FailureReport(command.FailureDescription, command.ResourceId, command.ReporterId, DateTime.Now, RepairStatusEnum.Waiting);

            return(await _failuresRepository.AddFailuresReport(failureReport));
        }
 public async Task UpdateFailureReport(FailureReport failureReport)
 {
     _context.FailureReports.Update(failureReport);
     await _context.SaveChangesAsync();
 }
 public async Task DeleteFailuresReport(FailureReport failureReport)
 {
     _context.FailureReports.Remove(failureReport);
     await _context.SaveChangesAsync();
 }
 private static bool InSameCategory(FailureReport failureReport)
 {
     return(failureReport.Items.GroupBy(item => item.Type.CategoryId).Count() == 1);
 }