public IActionResult Create([FromForm] CreateBreweryDTO newBrewery) // /api/brewery { if (!ModelState.IsValid) { return(StatusCode(422, ModelState)); } var result = _breweryService.CreateBrewery(newBrewery); if (result.IsError) { return(StatusCode(422, result.Errors)); } return(Ok(result.SuccessResult)); }
public ServiceResult <int> CreateBrewery(CreateBreweryDTO brewery) { var newBrewery = _mapper.Map <Brewery>(brewery); _breweryRepostiory.Insert(newBrewery); if (brewery.Image == null) { return(new ServiceResult <int>(newBrewery.Id)); } var imageSaveResult = _imageService.SaveImage(newBrewery.Id, brewery.Image, Path.Combine("images", "breweries")); if (imageSaveResult.IsError) { return(new ServiceResult <int>("Failed to save the image")); } newBrewery.ImagePath = imageSaveResult.SuccessResult; //zapis sciezki do pliku obrazka w bazie _breweryRepostiory.Update(newBrewery); return(new ServiceResult <int>(newBrewery.Id)); }