public async Task <ActionResult <ActorLookupDto> > Add([FromBody] ActorLookupDto actor) { if (!ModelState.IsValid) { return(BadRequest(new ActorLookupDtoValidator().Validate(actor).Errors)); } try { var model = await _repository.AddAsync(actor); //await _actorPhotosRepository.AddAsync(new ActorPhotoLookupDto{ActorId = model.ActorId, Path = "Hello path"}); //foreach(var photo in actor.Photos) //{ // await _actorPhotosRepository.AddAsync(new ActorPhotoLookupDto { ActorId = model.ActorId, Path = photo.Path }); //} //model.Photos = _actorPhotosRepository.Find(e => e.ActorId == model.ActorId); return(Ok(model)); } // TODO: Specify more specific exceptions. catch (Exception) { return(BadRequest(new ActorLookupDto { Errors = new List <string> { "Error at add entity." } })); } }
public async Task <ActionResult> PhotoUpload(int id) { var photosUploadMulti = Request.Form.Files; foreach (var file in photosUploadMulti) { if (file == null) { continue; } var newFileName = $"{Guid.NewGuid()}{Path.GetExtension(Path.GetFileName(file.FileName))}"; var path = Path.Combine(Directory.GetCurrentDirectory(), "actorsPhotosDir"); await using (var fileStream = new FileStream(Path.Combine(path, newFileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } var tmp = new ActorPhotoLookupDto { ActorId = id, Path = $"{newFileName}" }; await _actorPhotosRepository.AddAsync(tmp); } return(Ok()); }
public async Task <int> AddBusiness(BusinessDto model) { return(await _service.AddAsync(new Business() { ProductId = model.ProductId, TotalPrice = model.TotalPrice, Number = model.Number, PayTypeId = model.PayTypeId })); }
public async Task <ActionResult <GenreLookupDto> > Add([FromBody] GenreLookupDto genre) { try { return(Ok(await _repository.AddAsync(genre))); } // TODO: Specify more specific exceptions. catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <FilmLookupDto> > Create([FromBody] FilmLookupDto film) { if (!ModelState.IsValid) { return(BadRequest(new FilmLookupDtoValidator().Validate(film).Errors)); } try { return(Ok(await _repository.AddAsync(film))); } // TODO: Specify more specific exceptions. catch (Exception) { return(BadRequest(new FilmLookupDto { Errors = new List <string> { "Error at add entity." } })); } }