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));
        }
        private bool IsDuplicateSubmit(FailureReportCreationDto dto, User user)
        {
            var time = DateTime.UtcNow.AddMinutes(-1);

            return(_failureRepo.GetAll().Any(rpt => rpt.Title == dto.Title &&
                                             rpt.ReporterId == user.Id &&
                                             rpt.Time >= time));
        }