예제 #1
0
        public async Task <ApiResponse <Video> > CreateVideo(VideoDto videoDto)
        {
            var response = new ApiResponse <Video>();

            try
            {
                //check video Exists
                var isExistVideo = await _videoRepository.CountAsync(i => i.Name == videoDto.Name);

                if (isExistVideo != 0)
                {
                    response.Success = false;
                    response.Errors.Add("Video Already Exists");
                    return(response);
                }

                var id = Guid.NewGuid();

                //create new video
                var video = Mapper.Map <Video>(videoDto);
                video.Id          = id;
                video.CreatedDate = DateTime.Now;
                video.IsActive    = true;
                await _videoRepository.AddAsyn(video);

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(ex.Message);
            }
            return(response);
        }