public async Task <IActionResult> CreateAsync( string Name, string Sex, float Weight, float Height, string Owner, IFormFile DogPicture, string Description, int Age) { if (Name != null && Sex != null && Owner != null && DogPicture != null && Description != null) { Dog dog = new Dog() { Name = Name, Sex = Sex, Weight = Weight, Height = Height, DogPicture = DogPicture.FileName, Description = Description, Age = Age, OwnerId = Owner }; // full path to file in temp location var filePath = Path.GetTempFileName(); var stream = new FileStream(filePath, FileMode.Create); await DogPicture.CopyToAsync(stream); stream.Close(); var result = await service.UploadPictureToS3Bucket(filePath, Path.GetExtension(DogPicture.FileName)); if (result != null) { //Set AWS S3 url to DogPicture property dog.DogPicture = result; var addedDog = await service.AddDog(dog, Owner); if (addedDog != null) { return(RedirectToAction("Index", new { info = "Dog was added sucessfully!" })); } } } string _error = "Please, complete the form below to successfully add a dog."; return(RedirectToAction("Create", new { Error = _error })); }
public ActionResult Post([FromBody] RequestModel dog) { _dogService.AddDog(dog); return(StatusCode(StatusCodes.Status201Created, $"The dog fact has been created.")); }