Esempio n. 1
0
        public Guid SendReport(InitialReport report)
        {
            var responsible = responsibleFounder.GetResponsible(report.Location);

            Console.WriteLine($"Found responsible: {JsonConvert.SerializeObject(responsible)}");
            if (!responsible.IsActive)
            {
                // todo(sivukhin, 18.05.2019): Handle inactive responsible case
                throw new Exception();
            }

            var fullReport = new Report
            {
                UserId        = report.UserId,
                Subject       = report.Subject,
                Location      = report.Location,
                ReportText    = report.ReportText,
                Attachments   = report.Attachments,
                CreationDate  = DateTime.UtcNow,
                ResponsibleId = responsible.Id,
            };
            var reportId = reportRepository.AddReport(fullReport);

            var user = userRepository.GetUser(report.UserId);

            emailRepository.AddEmail(new EmailMessage
            {
                Body           = messageExtender.ExtendReportText(responsible, user, fullReport),
                Subject        = messageExtender.ExtendSubject(fullReport),
                RecipientEmail = responsible.Email,
                ResponsibleId  = responsible.Id,
                Attachments    = report.Attachments,
            });
            return(reportId);
        }
Esempio n. 2
0
        public int AddReport(AppReport report)
        {
            Domain.MainBoundedContext.Reports.Aggregates.Report r = report.ToReport();

            // owners
            r.Owners = new List <User>();
            foreach (var o in report.Owners)
            {
                r.Owners.Add(_userRepository.GetFiltered((u) => u.Id == o.Id).FirstOrDefault());
            }

            // team
            // r.TeamSite = _teamRepository.Get(report.Team.Id.GetValueOrDefault());

            // category
            r.Catagories = new List <Category>();
            foreach (var category in report.Categories)
            {
                r.Catagories.Add(_categoryRepository.Get(category.Id.GetValueOrDefault()));
            }

            // Tags
            r.Tags = new List <Tag>();
            foreach (var t in report.Tags)
            {
                r.Tags.Add(_tagRepository.Get(t.Id.GetValueOrDefault()));
            }


            return(_reportRepository.AddReport(r));
        }
Esempio n. 3
0
        public void Add(IEnumerable <ReportDto> reportdto)
        {
            try
            {
                List <ReportEntity> newReportList = new List <ReportEntity>();

                reportdto.ToList().ForEach(e =>
                {
                    newReportList.Add(ReportEntity.Create(_mapper.Map <ReportDto, ReportEntity>(e)));
                });

                if (newReportList != null)
                {
                    _reportRepository.AddReport(newReportList);
                    _rALUnitOfWork.Save();

                    newReportList.ToList().ForEach(e =>
                    {
                        logCentral.Info(string.Format("Report {0} has been created", e.id));
                    });
                }
                else
                {
                    logCentral.Info("Create Report: Invalid Role information");
                }
            }
            catch (Exception ex)
            {
                logCentral.Error("Create Report", ex);
                throw;
            }
        }
        public async Task <ActionResult> Create(Report report, int truckId)
        {
            //report.Identity = await _userManager.GetUserAsync(User);
            report.Truck = await _truckRepository.GetTruck(truckId);

            await _reportRepository.AddReport(report);

            return(RedirectToAction("IndexReport"));
        }
Esempio n. 5
0
        public void AddReport(AddReportRequest request)
        {
            if (request.PostId.HasValue && request.CommentId.HasValue)
            {
                throw new ArgumentException("Cannot report comment and post at the same time");
            }

            var report = _newReportMapper.Map(request);

            _reportRepository.AddReport(report);
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateReport([Bind("Title, LocationOfReport, DateTimeOfReport, TypeOfHazard, Description, Status, ImageToUpload")] ReportViewModel newReport)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string fileName = "";

                    if (newReport.ImageToUpload != null)
                    {
                        // Store image locally
                        var extension = "." + newReport.ImageToUpload.FileName.Split('.')[newReport.ImageToUpload.FileName.Split('.').Length - 1];
                        fileName = Guid.NewGuid().ToString() + extension;
                        var path = Directory.GetCurrentDirectory() + "\\wwwroot\\images\\reports\\" + fileName;
                        using (var bits = new FileStream(path, FileMode.Create))
                        {
                            newReport.ImageToUpload.CopyTo(bits);
                        }
                    }

                    // Create Object
                    Report report = new Report()
                    {
                        Title            = newReport.Title,
                        CreatedOn        = DateTime.UtcNow,
                        ModifiedOn       = DateTime.UtcNow,
                        LocationOfReport = newReport.LocationOfReport,
                        DateTimeOfReport = newReport.DateTimeOfReport,
                        TypeOfHazard     = newReport.TypeOfHazard,
                        Description      = newReport.Description,
                        Status           = newReport.Status,
                        Image            = "/images/reports/" + fileName,
                        Reporter         = await _userManager.GetUserAsync(User)
                    };

                    _logger.LogInformation("User: "******", created a report");
                    _reportRepository.AddReport(report);
                    return(RedirectToAction("ViewReports"));
                }
                else
                {
                    return(View(newReport));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(View("Error"));
            }
        }
        public void AddReport(CreateReportDto report)
        {
            var dog = _dogService.Add(report.Dog);

            var reportEntity = new ReportEntity
            {
                ContactEmail  = report.ContactEmail,
                ContactNumber = report.ContactNumber,
                DateReported  = DateTime.UtcNow,
                DogId         = dog.Id
            };

            _reportRepository.SaveAll();
            _reportRepository.AddReport(reportEntity);
            _reportRepository.SaveAll();
        }
Esempio n. 8
0
        public async Task <Report> GetReportAsync(string userName)
        {
            userName = userName.Trim().ToLower();
            var report = await _reportRepository.GetReportAsync(userName);

            if (report == null)
            {
                report = await _reportBuilder.BuildReportAsync(userName);

                if (report != null)
                {
                    report.UserId = _currentUserId;
                    _reportRepository.AddReport(report);
                    await _reportRepository.SaveChangesAsync();
                }
            }
            return(report);
        }
Esempio n. 9
0
        public async Task <ActionResult> ReportUser([FromBody] ReportForCreationDto reportForCreationDto)
        {
            var userReporter = await _userRepo.GetUserByUserClaims(HttpContext.User);

            if (userReporter == null)
            {
                return(Unauthorized("User is Unauthorized"));
            }

            var userReported = await _userRepo.GetUserByUsername(reportForCreationDto.Username);

            if (userReported == null)
            {
                return(BadRequest("User Not Found"));
            }
            if (userReporter.Id == userReported.Id)
            {
                return(BadRequest("You Can't Report Yourself"));
            }
            var lastReportDate = await _reportRepo.GetLastReportDate(userReporter.Id, userReported.Id);

            if (DateTime.Now < lastReportDate.AddDays(1))
            {
                return(BadRequest("User Can't Report Same User more than once in a day"));
            }
            var newReport = new Report
            {
                UserSourceReportId      = userReporter.Id,
                UserDestinationReportId = userReported.Id,
                ReportString            = reportForCreationDto.ReportString,
                ReportDate = DateTime.Now
            };
            var result = await _reportRepo.AddReport(newReport);

            if (result)
            {
                return(Ok("Report done successfully"));
            }

            throw new Exception("Error Occured While Reporting User");
        }
Esempio n. 10
0
        public async Task TryGenerateReports()
        {
            _logger.LogInformation("Starting CDC report generation task");
            try
            {
                var lastReportingPeriod = _periods.GetLastReportingPeriodBeforeDate(FundingSource.CDC, _dateTime.UtcNow.Date);

                var createdReportsCount = 0;
                var organizations       = _organizations.GetOrganizationsWithFundingSpaces(FundingSource.CDC);
                foreach (var organization in organizations)
                {
                    // If report has not been created for last reporting period, create it
                    if (!_reports.HasCdcReportForOrganizationAndReportingPeriod(organization.Id, lastReportingPeriod))
                    {
                        var previousReport = _reports.GetMostRecentSubmittedCdcReportForOrganization(organization.Id);
                        var report         = new CdcReport
                        {
                            OrganizationId    = organization.Id,
                            ReportingPeriodId = lastReportingPeriod.Id,
                            Accredited        = previousReport != null && previousReport.Accredited,
                        };

                        _reports.AddReport(report);
                        createdReportsCount += 1;
                    }
                }

                await _reports.SaveChangesAsync();

                _logger.LogInformation($"Successfully created {createdReportsCount} reports for reporting period {lastReportingPeriod.Period.Date}");
            }
            catch (Exception e)
            {
                // TODO: figure out how to alert on this when alerting exists
                _logger.LogError($"Unable to create reports", e);
            }
        }
Esempio n. 11
0
        public async Task <Report> AddReport(ReportResource report, User user)
        {
            var status = await _reportRepository.GetReportStatus(1); // 1 - в обработке

            byte[]      photo          = Convert.FromBase64String(report.ReportPhoto);
            ReportPhoto newReportPhoto = new ReportPhoto
            {
                Photo = photo
            };
            Report newReport = new Report
            {
                Description  = report.Description,
                Latitude     = report.Latitude,
                Longitude    = report.Longitude,
                RegionName   = await GetLocationRegion(report.Latitude, report.Longitude),
                User         = user,
                ReportStatus = status,
                ReportType   = report.ReportType
            };

            await _reportRepository.AddReport(newReport, newReportPhoto);

            return(newReport);
        }
        public async Task <bool> AddReport(DomainModel.Report reportData)
        {
            var examQuestionsData = new Infrastructure.DataModel.ExamQuestion()
            {
                ExamId              = reportData.ExamId,
                InputUnitOfMeasure  = reportData.InputUnitOfMeasure,
                InputValue          = reportData.InputValue,
                StudentID           = reportData.StudentID,
                StudentName         = reportData.StudentName,
                StudentResponse     = reportData.StudentResponse,
                IsCorrect           = reportData.IsCorrect,
                OutPutUnitOfMeasure = reportData.OutPutUnitOfMeasure,
                TeacherName         = reportData.TeacherName
            };
            var reportToAdd = new Report.Infrastructure.DataModel.Report()
            {
                ExamDate        = reportData.ExamDate,
                ExamDescription = reportData.ExamDescription,
                ExamId          = reportData.ExamId,
                ExamQuestion    = examQuestionsData
            };

            return(await _reportRepository.AddReport(reportToAdd));
        }
Esempio n. 13
0
 public async Task AddReport(ReportToAddDto reportToAdd)
 {
     var companyId = (Guid)_soldierRepository.GetById(reportToAdd.SoldierId).Result.CompanyId;
     var report    = ReportMapper.AddReportMap(reportToAdd, companyId);
     await _reportRepository.AddReport(report);
 }
 public IActionResult AddReport(Report r)
 {
     _repo.AddReport(r);
     return(View());
 }