Пример #1
0
        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"));
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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));
        }
Пример #4
0
 public bool Insert(Actor actor)
 {
     _repository.Create(actor);
     return(_repository.SaveChanges());
 }