public async Task <IActionResult> PostCamera([FromBody] Common.Models.Camera camera) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var user = await this.userHelper.GetUserByEmailAsync(camera.User.Email); if (user == null) { return(this.BadRequest("Invalid user")); } var city = await this.cityRespository.GetCityByIdAsync(camera.CityId); if (city == null) { return(this.BadRequest("Invalid city")); } // Image part var imageUrl = string.Empty; if (camera.ImageArray != null && camera.ImageArray.Length > 0) { var stream = new MemoryStream(camera.ImageArray); var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; var folder = "wwwroot\\images\\cameras"; var fullPath = $"{file}"; var response = FilesHelper.UploadPhoto(stream, folder, file); // si puede subir la imagen if (response) { imageUrl = fullPath; } } else { imageUrl = camera.ImageUrl; } var entityCamera = new Camera { Name = camera.Name, Comments = camera.Comments, CreatedDate = DateTime.Now, Latitude = camera.Latitude, Longitude = camera.Longitude, User = user, CityId = camera.CityId, City = city, ImageUrl = imageUrl }; var newCamera = await cameraRepository.CreateAsync(entityCamera); return(Ok(newCamera)); }