public async Task <IActionResult> CreateActor([FromBody] CreateActorDTO actorDto) { try { if (actorDto == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var actorObj = _mapper.Map <Actor>(actorDto); var success = await _actorRepo.Create(actorObj); if (!success) { ModelState.AddModelError("", $"Something went wrong when creating the record"); return(StatusCode(500, ModelState)); } return(Created("Succesfully Created", new { actorObj })); } catch (Exception E) { return(StatusCode(500, "Something went wrong. Please contact your admin")); } }
public void Create(ActorDTO actorDTO) { Actor actor = new Actor { Id = Guid.NewGuid().ToString(), FirstName = actorDTO.FirstName, LastName = actorDTO.LastName, Picture = actorDTO.Picture, Age = actorDTO.Age }; _actorRepository.Create(actor); }
public IActionResult Create(ActorCreateModel actorCreateModel) { //Actor actor = new Actor(); //actor.Name = actorCreateModel.Name; //actor.Surname = actorCreateModel.Surname; //actor.Age = actorCreateModel.Age; //_actorRepository.Create(actor); //return Ok(actorCreateModel); Actor actor = _mapper.Map <Actor>(actorCreateModel); foreach (var actor1 in actorCreateModel.MovieId) { ActorMovie actorMovie = new ActorMovie(); actorMovie.Movie = _movieRepository.GetById(actor1); actor.Movies.Add(actorMovie); } ActorResponseModel actorResponse = _mapper.Map <ActorResponseModel>(_actorRepository.Create(actor)); return(Ok(actorResponse)); }
public bool Insert(Actor actor) { _repository.Create(actor); return(_repository.SaveChanges()); }