public async Task <ActionResult <ActorModel> > Post(ActorModel model) { try { var existing = _actorRepository.GetActorByNameAsync(model.LastName, model.FirstName); if (existing != null) { return(Conflict( $"The actor, {model.FirstName} {model.LastName}, already exists in the database.")); } var actor = _mapper.Map <Actor>(model); actor.Id = _actorRepository.GenerateActorId(); var location = _linkGenerator.GetPathByAction("Get", "Actors", new { actorId = actor.Id }); _actorRepository.Add(actor); if (await _actorRepository.SaveChangesAsync()) { return(Created(location, _mapper.Map <ActorModel>(actor))); } return(Problem($"The actor, {model.FirstName} {model.LastName}, was not created.", "Add Actor", StatusCodes.Status304NotModified)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task AddPost(ActorAddDto actor) { var newActor = _mapper.Map <Actor>(actor); await _actorRepository.UploadImage(actor.ImageFile, newActor); await _actorRepository.Add(newActor); foreach (var movie in actor.MovieIds) { await _movieActorRepository.Add(new MovieActor() { MovieId = movie, ActorId = newActor.Id }); } //foreach (var movie in actor.MovieIds) //{ // var newMovieActor = new MovieActor() // { // MovieId = movie, // ActorId = newActor.Id // }; // await _movieActorRepository.Add(newMovieActor); //} DO PRZETESTOWANIA Z MAPPEREM }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { Guid transactionId = CombGuid.Generate(); T actor = (T)Activator.CreateInstance(typeof(T), new[] { transactionId, context, cb, extraData }); _actorRepository.Add(actor); AsyncCallback callback = x => { _actorRepository.Remove(actor); context.Response.Write("Repository Size: " + _actorRepository.Count()); cb(x); }; IAsyncResult asyncResult = actor.BeginAction(context, callback, extraData); _bus.Endpoint.Send(new InitiateStockQuoteRequestImpl { RequestId = transactionId, Symbol = "AAPL" }); return(asyncResult); }
public async Task <ActionResult> Create(AddUpdateActorCommand command) { if (!ModelState.IsValid) { return(View()); } await repository.Add(command); return(RedirectToAction(nameof(Index))); }
public async Task <Actor> Create(CreateActor data, [Service] IActorRepository repository, [Service] ICountryRepository countries) { var country = await countries.GetByIso(data.Nationality); var actor = new Actor(data.Name, data.DateOfBirth, country); await repository.Add(actor); return(actor); }
public async Task AddPost(MovieAddDto movie) { var newMovie = _mapper.Map <Movie>(movie); await _movieRepository.UploadImage(movie.ImageFile, newMovie); await _movieRepository.Add(newMovie); foreach (var newActorDto in movie.NewActors) { var newActor = _mapper.Map <Actor>(newActorDto); await _actorRepository.Add(newActor); await _actorRepository.UploadImage(newActorDto.ImageFile, newActor); await _movieActorRepository.Add(new MovieActor() { MovieId = newMovie.Id, ActorId = newActor.Id }); } foreach (var actor in movie.ActorIds) { await _movieActorRepository.Add(new MovieActor() { MovieId = newMovie.Id, ActorId = actor }); } foreach (var category in movie.CategoryIds) { await _movieCategoryRepository.Add(new MovieCategory() { MovieId = newMovie.Id, CategoryId = category }); } }
public async Task Post_CallsRepository() { var actorCommand = new AddUpdateActorCommand { Id = 1, Description = "Description", Name = "Name" }; var command = new CreateActorCommand(); command.ActorCommand = actorCommand; AddUpdateActorCommand repoCommand = new AddUpdateActorCommand(); Mock.Arrange(() => repo.Add(Arg.IsAny <AddUpdateActorCommand>())) .Returns((AddUpdateActorCommand cmd) => { repoCommand = cmd; return(Task.FromResult(cmd.Id)); }); await target.Post(command); Assert.Equal(command.ActorCommand.Id, repoCommand.Id); Assert.Equal(command.ActorCommand.Description, repoCommand.Description); Assert.Equal(command.ActorCommand.Name, repoCommand.Name); }
public async Task <ActionResult> Post([FromBody] CreateActorCommand command) { if (command == null) { return(HttpBadRequest()); } var id = await repository.Add(command.ActorCommand); command.ActorCommand.Id = id; foreach (var link in command?.Links ?? new List <CreateLinkForNewNodeCommand>()) { await linkDataService.Add(link.ToCreateLinkCommand(id, StoryboardNodeTypes.Actor)); } return(CreatedAtAction(nameof(GetById), new { id = id }, command)); }
public async Task <IActionResult> CreateActor([FromBody] ActorResource actorResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var actor = mapper.Map <ActorResource, Actor>(actorResource); repository.Add(actor); await unitOfWork.CompleteAsync(); actor = await repository.GetActor(actor.Id); var result = mapper.Map <Actor, ActorResource>(actor); return(Ok(result)); }
public async Task <ActionResult <ActorDTO> > PostActor(ActorDTO actorDto) { try { var mappedEntity = _mapper.Map <Actor>(actorDto); _actorRepository.Add(mappedEntity); if (await _actorRepository.Save()) { return(Created($"/api/v1.0/actors/{mappedEntity.ActorID}", _mapper.Map <ActorDTO>(mappedEntity))); } } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}")); } return(BadRequest()); }
public async Task <IActionResult> CreateActor([FromBody] ActorDTO actorDTO) { try { var actor = _mapper.Map <Actor>(actorDTO); var actorFromRepo = await _repository.Add(actor); if (actorFromRepo != null) { return(CreatedAtAction(nameof(GetActorById), new { id = actor.Id }, actor)); } return(BadRequest("Failed to create actor.")); } catch (Exception e) { var result = new { Status = StatusCodes.Status500InternalServerError, Data = $"Failed to create the actor. Exception thrown when attempting to add data to the database: {e.Message}" }; return(this.StatusCode(StatusCodes.Status500InternalServerError, result)); } }
private async Task <ActorViewModel> CreateActor(ActorViewModel model) { var actor = await _actorRepository.Add(_mapper.Map <Actor>(model)); return(_mapper.Map <ActorViewModel>(actor)); }
public async Task AddAndSave(Actor actor) { _actorRepo.Add(actor); await _actorRepo.Save(); }
public ActorCreationData Add(ActorCreationData entity) { return(_actorRepository.Add(entity)); }