コード例 #1
0
        public async Task <IActionResult> CreateEpisode(int id, [FromForm] EpisodeRequest model)
        {
            var movie = _movieRepository.FindById(id);

            if (!ModelState.IsValid || movie == null || model.File == null)
            {
                return(BadRequest(ErrorResponse.InvalidPayload));
            }

            var episode = new EpisodeEntity()
            {
                Name    = model.Name,
                MovieId = movie.Id,
            };

            var filePath = $"/{DateTime.Now.ToFileTime()}_{model.File.FileName}";

            using (var stream = new FileStream($"wwwroot/{filePath}", FileMode.Create))
            {
                await model.File.CopyToAsync(stream);

                episode.Url = filePath;
            }

            _episodeRepository.Add(episode);

            await _unitOfWork.SaveChangesAsync();

            return(Ok());
        }
コード例 #2
0
ファイル: Module.cs プロジェクト: Denrage/Cida
 public override async Task <EpisodeResponse> GetEpisodes(EpisodeRequest request, ServerCallContext context)
 {
     return(new EpisodeResponse()
     {
         Episodes = { (await this.cache.GetEpisodesAsync(request.Id, context.CancellationToken)).Select(x => x.ToGrpc()).ToArray() }
     });
 }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [FromForm] EpisodeRequest model)
        {
            var episode = _episodeRepository.FindById(id);

            if (!ModelState.IsValid || episode == null)
            {
                return(BadRequest(ErrorResponse.InvalidPayload));
            }

            episode.Name = model.Name;

            if (model.File != null)
            {
                var filePath = $"/{DateTime.Now.ToFileTime()}_{model.File.FileName}";
                using (var stream = new FileStream($"wwwroot/{filePath}", FileMode.Create))
                {
                    var oldPath = $"wwwroot{episode.Url}";
                    if (System.IO.File.Exists(oldPath))
                    {
                        System.IO.File.Delete(oldPath);
                    }

                    await model.File.CopyToAsync(stream);

                    episode.Url = filePath;
                }
            }

            _episodeRepository.Update(episode);
            await _unitOfWork.SaveChangesAsync();

            return(Ok());
        }
コード例 #4
0
        public async Task <EpisodeProgressResponse> GetEpisodeProgressAsync(EpisodeRequest episodeRequest)
        {
            string url = _baseApiAddress + $"progress?";

            var parameters = new Dictionary <string, string>();

            ExtractParametersFromEpisodeRequest(episodeRequest, parameters);

            url += string.Join("&", parameters.Select(param => $"{param.Key}={param.Value}"));

            return(await HttpClient.GetAsync <EpisodeProgressResponse>(url));
        }
コード例 #5
0
        public void UpdateEpisode__WithNullRequest()
        {
            #region Arrange
            var            controller = new StarsWarsDetailsController(_starsWarsManager);
            EpisodeRequest request    = null;
            #endregion

            #region Act
            var response = controller.UpdateEpisode(request);
            #endregion

            #region Assert
            Assert.IsInstanceOfType(response, typeof(BadRequestErrorMessageResult));
            #endregion
        }
コード例 #6
0
        public IHttpActionResult UpdateEpisode(EpisodeRequest request)
        {
            try
            {
                _log.Info("begin UpdateEpisode");

                if (request == null)
                {
                    throw new ArgumentNullException("The request content was null or not in the correct format");
                }

                _starsWarsManager.UpdateEpisode(Mapper.Map <Episode>(request));

                return(Ok(new EpisodeResponse()
                {
                    Data = request
                }));
            }
            catch (ArgumentNullException argEx)
            {
                _log.Error(argEx);

                return(BadRequest(argEx.Message));
            }
            catch (StarsWarsException swEx)
            {
                _log.Error(swEx);

                return(Content <EpisodeResponse>((HttpStatusCode)422, new EpisodeResponse {
                    Message = swEx.Message
                }));
            }
            catch (EntityNotFoundException enEx)
            {
                _log.Error(enEx);

                return(Content <EpisodeResponse>(HttpStatusCode.NotFound, new EpisodeResponse {
                    Message = enEx.Message
                }));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(Content <EpisodeResponse>(HttpStatusCode.InternalServerError, new EpisodeResponse {
                    Message = ex.Message
                }));
            }
        }
コード例 #7
0
        public async Task <EpisodeProgressResponse> SaveEpisodeProgressAsync(EpisodeRequest episodeRequest)
        {
            string url = _baseApiAddress + $"progress";

            var parameters = new Dictionary <string, string>();

            ExtractParametersFromEpisodeRequest(episodeRequest, parameters);

#if __IOS__ || __ANDROID__ || NET45
            var content = new FormUrlEncodedContent(parameters);
#endif
#if NETFX_CORE
            var content = new HttpFormUrlEncodedContent(parameters);
#endif

            return(await HttpClient.PostAsync <EpisodeProgressResponse>(url, content));
        }
コード例 #8
0
        public void AddEpisode__WithGoodRequest()
        {
            #region Arrange
            var            controller  = new StarsWarsDetailsController(_starsWarsManager);
            int            characterId = 7;
            EpisodeRequest request     = new EpisodeRequest()
            {
                Name = "NEWHOPE"
            };
            #endregion

            #region Act
            var response = controller.AddEpisode(characterId, request);
            #endregion

            #region Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
            #endregion
        }
コード例 #9
0
        public void UpdateEpisode__WithGoodRequest()
        {
            #region Arrange
            var            controller = new StarsWarsDetailsController(_starsWarsManager);
            EpisodeRequest request    = new EpisodeRequest()
            {
                Id   = 11,
                Name = "EMPIRE"
            };
            #endregion

            #region Act
            var response = controller.UpdateEpisode(request) as OkNegotiatedContentResult <EpisodeResponse>;
            #endregion

            #region Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            #endregion
        }
コード例 #10
0
        public void AddEpisode__DuplicatedRequest()
        {
            #region Arrange
            var            controller  = new StarsWarsDetailsController(_starsWarsManager);
            int            characterId = 7;
            EpisodeRequest request     = new EpisodeRequest()
            {
                Name = "NEWHOPE"
            };
            #endregion

            #region Act
            var response = controller.AddEpisode(characterId, request) as NegotiatedContentResult <EpisodeResponse>;
            #endregion

            #region Assert
            Assert.IsNotNull(response);
            Assert.AreEqual("Episode already exists", response.Content.Message);
            Assert.AreEqual(422, (int)response.StatusCode);
            #endregion
        }
コード例 #11
0
        public void UpdateEpisode__WithNotFound()
        {
            #region Arrange
            var            controller = new StarsWarsDetailsController(_starsWarsManager);
            EpisodeRequest request    = new EpisodeRequest()
            {
                Id   = 1,
                Name = "EMPIRE"
            };
            #endregion

            #region Act
            var response = controller.UpdateEpisode(request) as NegotiatedContentResult <EpisodeResponse>;
            #endregion

            #region Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.AreEqual($"Episode {request.Name} not found", response.Content.Message);
            Assert.AreEqual(404, (int)response.StatusCode);
            #endregion
        }
コード例 #12
0
        public async Task <Response> MarkEpisodeWatchedAsync(EpisodeRequest episodeRequest, bool publishOnFacebook, bool publishOnTwitter, bool autoFollow = true)
        {
            string url = _baseApiAddress + $"checkin";

            var parameters = new Dictionary <string, string>();

            ExtractParametersFromEpisodeRequest(episodeRequest, parameters);

            parameters.Add("publish_on_ticker", publishOnFacebook ? "1" : "0");
            parameters.Add("publish_on_twitter", publishOnTwitter ? "1" : "0");
            parameters.Add("auto_follow", autoFollow ? "1" : "0");


#if __IOS__ || __ANDROID__ || NET45
            var content = new FormUrlEncodedContent(parameters);
#endif
#if NETFX_CORE
            var content = new HttpFormUrlEncodedContent(parameters);
#endif

            return(await HttpClient.PostAsync <Response>(url, content));
        }
コード例 #13
0
        private void ExtractParametersFromEpisodeRequest(EpisodeRequest episodeRequest, Dictionary <string, string> parameters)
        {
            if (episodeRequest is EpisodeRequestByEpisodeId episodeRequestByEpisodeId)
            {
                parameters.Add("episode_id", episodeRequestByEpisodeId.EpisodeId.ToString());
            }

            if (episodeRequest is EpisodeRequestByFilename episodeRequestByFilename)
            {
                parameters.Add("filename", episodeRequestByFilename.Filename);
            }

            if (episodeRequest is EpisodeRequestByImdbId episodeRequestByImdbId)
            {
                parameters.Add("imdb_id", episodeRequestByImdbId.ImdbId);
            }

            if (episodeRequest is EpisodeRequestByShowData episodeRequestByShowData)
            {
                parameters.Add("show_id", episodeRequestByShowData.ShowId.ToString());
                parameters.Add("season_number", episodeRequestByShowData.Season.ToString());
                parameters.Add("number", episodeRequestByShowData.Number.ToString());
            }
        }
コード例 #14
0
 public IObservable <BooleanResponse> GetIsEpisodeWatched(EpisodeRequest episodeRequest)
 {
     return(_apiService.GetIsEpisodeWatchedAsync(episodeRequest).ToObservable());
 }
コード例 #15
0
 public IObservable <EpisodeProgressResponse> SaveEpisodeProgress(EpisodeRequest episodeRequest)
 {
     return(_apiService.SaveEpisodeProgressAsync(episodeRequest).ToObservable());
 }
コード例 #16
0
 public IObservable <Response> UnmarkEpisodeWatched(EpisodeRequest episodeRequest)
 {
     return(_apiService.UnmarkEpisodeWatchedAsync(episodeRequest).ToObservable());
 }
コード例 #17
0
 public IObservable <Response> MarkEpisodeWatched(EpisodeRequest episodeRequest, bool publishOnFacebook, bool publishOnTwitter, bool autoFollow = true)
 {
     return(_apiService.MarkEpisodeWatchedAsync(episodeRequest, publishOnFacebook, publishOnTwitter, autoFollow).ToObservable());
 }
コード例 #18
0
 public IObservable <EpisodeResponse> GetEpisode(EpisodeRequest episodeRequest)
 {
     return(_apiService.GetEpisodeAsync(episodeRequest).ToObservable());
 }