public async Task <IActionResult> Create([FromForm] IncidentViewModel incidentViewModel) { if (incidentViewModel.Description.ToLower().Contains("space") && incidentViewModel.Description.ToLower().Contains("invader")) { return(RedirectToAction("Index", "Invaders")); } var imageName = $"{Guid.NewGuid().ToString()}.jpg"; var imageStream = new MemoryStream(); incidentViewModel.File.CopyTo(imageStream); imageStream.Position = 0; var newIncidentInput = new CreateIncidentInput { Description = incidentViewModel.Description, Longitude = incidentViewModel.Longitude, Latitude = incidentViewModel.Latitude, Time = DateTime.Now, ImageName = imageName, ImageBytes = ReadFully(imageStream) }; _incidentAppService.RecordNewIncident(newIncidentInput); await _imageStorageService.UploadImageBytes(imageName, imageStream.GetAllBytes()); return(View("Index")); }
public async Task <IActionResult> RecordIncident([FromBody] IncidentModel incident) { var imageName = $"{Guid.NewGuid().ToString()}.jpg"; var imageBytes = Convert.FromBase64String(incident.Image); await _imageStorageService.UploadImageBytes(imageName, imageBytes); var newIncidentInput = new CreateIncidentInput { Description = incident.Description, Longitude = incident.Position.Longitude, Latitude = incident.Position.Latitude, Time = DateTime.Now, ImageName = imageName, ImageBytes = imageBytes }; _incidentAppService.RecordNewIncident(newIncidentInput); return(Ok()); }