public IActionResult Submit(Reports report)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (!ModelState.IsValid)
            {
                return(View("Create"));
            }
            else
            {
                report.UserId = _userManager.GetUserId(User);
                _reportRepository.CreateReport(report);

                try
                {
                    _reportRepository.Email(report);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(StatusCode(500, "Email Address was invailid"));
                }

                return(View());
            }
        }
Пример #2
0
        public JsonResult GetImages(string image1, string image2, string image3, string image4, string image5, string image6, string image7, string image72, int min, int max, string date, Report report)
        {
            Report model = new Report();

            if (date.Contains('/'))
            {
                string[] ar = date.Split('/');
                date = ar[1] + '.' + ar[0] + '.' + ar[2];
                if (date.Contains(" AM"))
                {
                    date = date.Replace(" AM", "");
                }
                else
                {
                    date = date.Replace(" PM", "");
                }
            }
            model.Date    = Convert.ToDateTime(date);
            model.image1  = image1;
            model.image2  = image2;
            model.image3  = image3;
            model.image4  = image4;
            model.image5  = image5;
            model.image6  = image6;
            model.image7  = image7;
            model.image72 = image72;
            model.from    = min;
            model.to      = max;
            Report rep = reportReporsitory.CreateReport(model);

            return(Json(rep.Id, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public async Task <IActionResult> CreateReport([Bind("LocationOfHazard", "DateOfSpottedHazard", "TypeOfHazard", "Description", "ImageToUpload")] EditReport newReport)
        {
            ViewBag.typesofhazard = new SelectList(hazardtypes);
            try
            {
                if (ModelState.IsValid)
                {
                    string fileName = "";
                    if (newReport.ImageToUpload != null)
                    {
                        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);
                        }
                    }
                    else
                    {
                        // Default image that's displayed if no image was uploaded
                        fileName = "default.png";
                    }

                    Report report = new Report()
                    {
                        Reporter            = await _userManager.GetUserAsync(User),
                        DateOfReport        = DateTime.UtcNow,
                        LocationOfHazard    = newReport.LocationOfHazard,
                        DateOfSpottedHazard = newReport.DateOfSpottedHazard,
                        TypeOfHazard        = newReport.TypeOfHazard,
                        Description         = newReport.Description,
                        ImageUrl            = "/images/reports/" + fileName,
                        Upvotes             = 0,
                        Status = "Open"
                    };

                    report.Reporter.NumberOfReports++; // increment number of reports

                    _logger.LogInformation("User " + User.Identity.Name + " created a report");

                    _reportRepository.CreateReport(report);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(newReport));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(View("Error"));
            }
        }
Пример #4
0
 void IReportService.CreateReport(CreateReportCommand command)
 {
     try
     {
         reportRepository.CreateReport(command.ToReportModel());
         reportRepository.Save();
     }
     catch (DbUpdateException)
     {
         throw;
     }
 }
Пример #5
0
        private async Task ExecuteCreateReportCommand()
        {
            if (string.IsNullOrWhiteSpace(Report.Title))
            {
                return;
            }
            if (DevicesCollection?.Count <= 0)
            {
                return;
            }
            Result = ButtonResult.OK;
            Report.ActiveDevices = _activeDevices.ToList();
            await _reportRepository.CreateReport(Report);

            CloseDialog(null);
        }
Пример #6
0
 private void HandleReport()
 {
     Report.LastUpdated = DateTime.Now;
     if (Report.Id == 0)
     {
         Report.ActiveDevices = DevicesColleciton.Where(x => x.IsAdded).ToList();
         _reportRepository.CreateReport(Report).Wait();
     }
     else if (_unChangedReport.IsEdited(Report))
     {
         _reportRepository.UpdateAsync(Report).Wait();
     }
     foreach (var device in DevicesColleciton)
     {
         device.ReportId = Report.Id;
         device.Report   = Report;
     }
 }
Пример #7
0
 public IActionResult Checkout(Reports report)
 {
     _reportRepository.CreateReport(report);
     return(View(report));
 }