public Task PublishEpisode(Episode episode) { PlaylistDto majedPlaylist = null; var serializer = new JsonSerializer(); var dtoToSave = EpisodeDto.CreateFromEpisode(episode); if (new FileInfo(SaveFileName).Exists) { using (var fileStream = File.OpenText(SaveFileName)) { var playlist = (PlaylistDto)serializer.Deserialize(fileStream, typeof(PlaylistDto)) ?? new PlaylistDto(); var existingEpisodes = playlist.Episodes ?? new EpisodeDto[0]; var concatenedEpisodes = existingEpisodes.Concat(new[] { dtoToSave }).ToArray(); majedPlaylist = new PlaylistDto { Episodes = concatenedEpisodes }; } File.Delete(SaveFileName); } else { majedPlaylist = new PlaylistDto { Episodes = new[] { dtoToSave } }; } using (var fileStream = File.CreateText(SaveFileName)) { serializer.Serialize(fileStream, majedPlaylist); } return(Task.CompletedTask); }
private async Task <int> SendNewEpisode(int count, EpisodeDto episodeDto, long chatId) { if (count >= 20) { Thread.Sleep(TimeSpan.FromSeconds(1)); count = 0; } var notifyMessage = "Вышла новая серия!\nСериал: " + episodeDto.TitleSeries + "\nСерия: " + episodeDto.TitleRu + "\nСсылка на серию: " + episodeDto.Link; var message = await _client.SendTextMessageAsync(chatId, notifyMessage); count++; if (message.Chat.Description == null) { return(count); } Thread.Sleep(TimeSpan.FromSeconds(2)); await _client.SendTextMessageAsync(chatId, notifyMessage); return(count); }
public void Given_Valid_Post_Data_Posts() { var tokenEnvironmentVariable = Environment.GetEnvironmentVariable("Token"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var c = new EpisodeDto { Description = "NewDesc", ConsultationId = 1, PatientId = 1, EndDate = DateTime.Now, StartDate = DateTime.Now, Priority = 10, IcpcCodeId = 1 }; var serialize = JsonConvert.SerializeObject(c); var content = new StringContent(serialize, Encoding.UTF8, "application/json"); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = _client.PostAsync("/api/Episodes/", content).Result; result.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.Created, result.StatusCode); }
public async Task <ActionResult <Episode> > CreateEpisode([FromBody] EpisodeDto episode) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entityEpisode = _mapper.Map <Episode>(episode); if (await _episodeRepository.EpisodeNameExistsAsync(episode.EpisodeName)) { return(BadRequest($"Episode name: {episode.EpisodeName} already exists")); } _episodeRepository.CreateEpisode(entityEpisode); await _episodeRepository.SaveChangesAsync(); return(CreatedAtAction( "GetEpisode", new { episodeId = entityEpisode.Id }, entityEpisode)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Task PublishEpisode(Enseignant enseignant, Episode episode) { var basePath = ConnectionPathProvider.GetSaveFileName(enseignant); var dtoToSave = EpisodeDto.CreateFromEpisode(episode); var playlistDto = LoadPlayListDto(basePath); playlistDto.Episodes = playlistDto.Episodes.Concat(new[] { dtoToSave }).ToArray(); File.WriteAllText(basePath, JsonConvert.SerializeObject(playlistDto)); //ecrasera le fichier si il existe return(Task.CompletedTask); }
public static EpisodeDto FromQueryResponse(this EpisodeDto dto, GetTvShowsCollectedResponse.Episode response) { if (response == null) { return(dto); } return(new EpisodeDto { Number = response.number }); }
public async Task <IActionResult> Put(int id, [FromBody] EpisodeDto updateEpisodeDto) { var episode = await _episodeRepository.Get(id); if (episode == null) { return(NotFound()); } if (updateEpisodeDto.ConsultationId != null) { var consultation = await _consultationRepository.Get(updateEpisodeDto.ConsultationId.Value); if (consultation == null) { return(BadRequest("Consult bestaat niet.")); } } if (updateEpisodeDto.PatientId != null) { var patient = await _patientRepository.Get(updateEpisodeDto.PatientId.Value); if (patient == null) { return(BadRequest("Patiënt bestaat niet.")); } } if (updateEpisodeDto.IcpcCodeId != null) { var icpcCode = await _icpcCodeRepository.Get(updateEpisodeDto.IcpcCodeId.Value); if (icpcCode == null) { return(BadRequest("ICPC Code bestaat niet.")); } } var userId = User.Claims.First(u => u.Type == ClaimTypes.Sid).Value; var currentUser = await _identityRepository.GetUserById(userId); _mapper.Map(updateEpisodeDto, episode); episode.Id = id; var updatedEpisode = await _episodeRepository.Update(episode, currentUser); var updatedEpisoded = _mapper.Map <Episode, EpisodeDto>(updatedEpisode); return(Ok(updatedEpisoded)); }
public async Task Given_Episode_To_Update_returns_200() { var entity = new EpisodeDto { Description = "UpdatedDesc" }; var result = await FakeController.Put(_fakeEntities[0].Id, entity); var objectResult = (OkObjectResult)result; Assert.NotNull(_fakeEntities[0].UpdatedAt); Assert.Equal(200, objectResult.StatusCode); }
public static EpisodeDto FromQueryResponse(this EpisodeDto dto, GetTvShowsWatchedResponse.Episode response) { if (response == null) { return(dto); } return(new EpisodeDto { Number = response.number, IsWatched = response.plays > 0 }); }
public static EpisodeDto FromQueryResponse(this EpisodeDto dto, GetEpisodesResponse.MediaContainerVideo queryResult) { if (queryResult == null) { return(dto); } return(new EpisodeDto { Number = queryResult.index, IsCompleted = queryResult.viewCount > 0, IdPlex = queryResult.ratingKey }); }
public static EpisodeDto FromQueryResponse(this EpisodeDto dto, GetEpisodesResponse.Episode response) { if (response == null) { return(dto); } return(new EpisodeDto { Id = response.id.ToString(), Number = response.episode_number, IsWatched = false }); }
public static EpisodeDto FromQueryResponse(this EpisodeDto dto, GetEpisodesResponse.Episode response) { if (response == null) { return(dto); } return(new EpisodeDto { Id = response.episodeid.ToString(), Number = response.episode, SeasonNumber = response.season, IsWatched = response.playcount > 0, FilePath = response.file }); }
public async Task <IActionResult> Update(int episodeId, [FromBody] EpisodeDto episodeDto) { if (await _episodeRepository.EpisodeNameExistsAsync(episodeDto.EpisodeName)) { return(BadRequest($"Episode with {episodeDto.EpisodeName} name exists already")); } var episode = _mapper.Map <Episode>(episodeDto); episode.Id = episodeId; _episodeRepository.UpdateEpisode(episode); await _episodeRepository.SaveChangesAsync(); return(CreatedAtAction( "GetEpisode", new { episodeId = episodeId }, episode)); }
public async Task Given_Episode_Posts_And_Returns_201_Code() { var entity = new EpisodeDto { Description = "NewDesc" }; var lengthBefore = _fakeEntities.Count; var result = await FakeController.Post(entity); var objActionResult = (CreatedAtActionResult)result.Result; var createdPatient = _fakeEntities[lengthBefore]; Assert.Equal(lengthBefore + 1, _fakeEntities.Count); Assert.Equal(201, objActionResult.StatusCode); Assert.Equal(createdPatient.Description, entity.Description); }
public EpisodeDto GetEpisode(long episodeId) { //I wanted to be consistent with episode_id property, //so that's why I am not fetching data by e.g. /films/1 //Value from URL does not fit with episode_id var json = WebClientHelper .GetJson("https://swapi.dev/api/films/", "results"); List <EpisodeDto> episodes = JsonConvert .DeserializeObject <List <EpisodeDto> >(json); var episode = episodes .Where(e => e.Episode_Id == episodeId) .FirstOrDefault(); if (episode == null) { throw new Exception("Episode doesn't exist"); } var episodeRating = _episodeRatingRepository .GetDbSet() .Where(er => er.EpisodeId == episodeId) .Select(er => er.Rating) .DefaultIfEmpty() .Average(); var episodeDto = new EpisodeDto { Episode_Id = episodeId, Title = episode.Title, Opening_Crawl = episode.Opening_Crawl, Director = episode.Director, Producer = episode.Producer, Release_Date = episode.Release_Date, Rating = episodeRating }; return(episodeDto); }
public IHttpActionResult PutEpisode(int id, EpisodeDto episodeDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != episodeDto.Id) { return(BadRequest()); } var episode = db.Episodes.SingleOrDefault(e => e.Id == id); if (episode == null) { return(NotFound()); } Mapper.Map(episodeDto, episode); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EpisodeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
protected override async Task OnInitializedAsync() { this.FormId = this.Parameters.Get <int>("FormId"); this.Id = this.Parameters.TryGet <int>("episode"); ((ModalService)this.ModalService).OnConfirm += this.OnConfirm; this.Model = new EpisodeShortModel { Description = "" }; this.Context = new EditContext(this.Model); if (this.Id != 0) { this.Episode = await this.EpisodeService.Get(this.Id); this.Model = new EpisodeShortModel(this.Episode); this.IsEdit = true; this.Context = new EditContext(this.Model); } }
public static EpisodeModel ToPodcastModel(this EpisodeDto podcastDto) { return(new EpisodeModel(podcastDto.Title, podcastDto.Url, podcastDto.PublicationDate)); }
public async Task <ActionResult <ActionResult <CharacterResult> > > AssignNewEpisodesWithCharacter(int characterId, EpisodeDto episodeForCharacter) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var character = _characterRepository.GetCharacter(characterId); if (character == null) { return(NotFound()); } await _characterService.AssignNewEpisodeToCharacter(character, _mapper.Map <Episode>(episodeForCharacter)); return(CreatedAtAction( "GetCharacter", new { characterId = characterId }, character)); }
/// <summary> /// Model from episode data object /// </summary> /// <param name="episode"></param> public EpisodeShortModel(EpisodeDto episode) { this.Description = episode.Description; this.Title = episode.Title; }