Пример #1
0
        public async Task <ResponseDto <BaseModelDto> > AddActor(AddActorBindingModel addActorBindingModel)
        {
            var response = new ResponseDto <BaseModelDto>();

            if (!Directory.Exists("wwwroot\\ActorsPictures"))
            {
                Directory.CreateDirectory("wwwroot\\ActorsPictures");
            }

            var fileName = Guid.NewGuid() + Path.GetExtension(addActorBindingModel.Photo.FileName);
            var filePath = Path.Combine("wwwroot\\ActorsPictures", fileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await addActorBindingModel.Photo.CopyToAsync(stream);
            }

            var actor = _mapper.Map <Actor>(addActorBindingModel);

            actor.Photo = fileName;

            var result = await _actorRepository.AddAsync(actor);

            if (!result)
            {
                File.Delete(filePath);
                response.AddError(Model.Actor, Error.actor_Adding);
                return(response);
            }

            return(response);
        }
Пример #2
0
        public async Task <IActionResult> AddActor([FromForm] AddActorBindingModel addActorBindingModel)
        {
            var result = await _actorService.AddActor(addActorBindingModel);

            if (result.ErrorOccurred)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }