public async Task <IActionResult> LoadFromText() { string jsonString = ReadWriteFile.ReadTextAsJson(@"g:\covertext.txt"); List <CoverModel> CoverList = JsonConvert.DeserializeObject <List <CoverModel> >(jsonString); List <CastModel> CastList = new List <CastModel>(); foreach (var cover in CoverList) { CastModel cast = new CastModel(); cast.firstname = cover.cast; cast.lastname = cover.filename; CastList.Add(cast); } // Sort CastList //List<CastModel> sortedCastList = CastList.OrderBy(x => x.firstname.ToLower()).ToList(); List <CastModel> sortedCastList = CastList; // Clear DBSet doruContext.CastSet.RemoveRange(doruContext.CastSet); foreach (var cast in sortedCastList) { doruContext.CastSet.Add(cast); } await doruContext.SaveChangesAsync(); return(NoContent()); }
public List <CastModel> getDirectorsByMovieId(int id) { PersonRepository dbPerson = new PersonRepository(); List <CastModel> tempList = new List <CastModel>(); IQueryable <cast> temp = getCast(id); foreach (cast c in temp) { if (c.role == 1) { person tempMen = dbPerson.getPersonById(c.person_id); CastModel tempModel = new CastModel(); tempModel.id = tempMen.id; tempModel.name = tempMen.name; tempModel.photo = tempMen.image_person.Where(i => i.is_portrait.Equals(true)) .FirstOrDefault() .id; tempList.Add(tempModel); } } return(tempList); }
public void Map_Maps_All_Properties_When_All_Needed_Properties_Arent_Null_Or_Empty() { // Arrange var expectedId = 1; var expectedName = "expectedName"; var expectedBirthday = new DateTime(2020, 10, 30); var instance = new CastModel { Person = new PersonModel { Id = expectedId, Name = expectedName, Birthday = expectedBirthday } }; var sut = CreateSut(); // Act var actual = sut.Map(instance); // Assert Assert.Equal(expectedId, actual.Id); Assert.Equal(expectedName, actual.Name); Assert.Equal(expectedBirthday, actual.Birthday); }
public async Task <ActionResult <IEnumerable <CastModel> > > MakeSortedCastDictionary() { List <CastModel> castList = new List <CastModel>(); Dictionary <string, List <string> > castDictionary = new Dictionary <string, List <string> >(); foreach (var Cast in doruContext.CastSet) { if (castDictionary.ContainsKey(Cast.firstname)) { // Add new value to list in dictionary value castDictionary[Cast.firstname].Add(Cast.lastname); } else { // Add new entry to dictionary List <string> coverList = new List <string>(); coverList.Add(Cast.lastname); castDictionary.Add(Cast.firstname, coverList); } } foreach (var dict in castDictionary) { CastModel cast = new CastModel(); cast.firstname = dict.Key; cast.lastname = dict.Value.Count().ToString(); castList.Add(cast); } return(castList); }
public async Task <ActionResult <CastModel> > PostCast([FromBody] CastModel Cast) { //CastModel Cast = new CastModel { label = "NewCast", filename = "New Cast" }; doruContext.CastSet.Add(Cast); await doruContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCast), new { id = Cast.Id }, Cast)); }
public void Map_Throws_ArgumentNullExecption_When_Person_Is_Null() { // Arrange var instance = new CastModel { Person = null }; var sut = CreateSut(); // Act & Assert Assert.Throws <ArgumentNullException>(() => sut.Map(instance)); }
public async Task <IActionResult> PutCast(long id, [FromBody] CastModel Cast) { if (id != Cast.Id) { return(BadRequest()); } doruContext.Entry(Cast).State = EntityState.Modified; await doruContext.SaveChangesAsync(); return(NoContent()); }
public static int CreateCast(string fname, string lname) { CastModel data = new CastModel { FirstName = fname, LastName = lname }; string sql = @"insert into dbo.Cast_Details(FirstName, LastName) values (@FirstName, @LastName);"; return(SqlDataAccess.SaveData <CastModel>(sql, data)); }
private CastModel Map(Cast cast) { if (cast == null) { return(null); } var castModel = new CastModel { Id = cast.ApiId, Name = cast.Name, Birthday = cast.Birthday?.ToString(DATETIME_FORMAT) }; return(castModel); }
public TvShowTest() { _castList = new List <CastModel>(); _castModel = new CastModel { Id = 7, Name = "Mackenzie Lintz", Birthday = "1996-11-22" }; _castList.Add(_castModel); _castModel = new CastModel { Id = 5, Name = "Colin Ford", Birthday = "1996-09-12" }; _castList.Add(_castModel); _tvShowModel = new TvShowModel { Id = 1, Name = "Under the Dome", Cast = _castList }; _mockCollection = new Mock <IMongoCollection <TvShowModel> >(); _mockCollection.Object.InsertOne(_tvShowModel); }
public async Task <ActionResult> MovieByPerson(string search) { int currentUserId = 0; if (Session["userId"] != null) { currentUserId = (int)Session["userId"]; } var baseAddress = new Uri("https://api.themoviedb.org/3/"); using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); using (var response = await httpClient.GetAsync($"person/{search}/movie_credits?api_key=0ac277c3f170caa0df815398709d9bb2&language=hu-BR")) { var myMovies = db.Watchlist.Where(m => m.UserID == currentUserId).Select(m => m.MovieId).ToList(); var myMoviesWatched = db.Watched.Where(m => m.UserId == currentUserId).Select(m => m.MovieId).ToList(); string jsonFile = await response.Content.ReadAsStringAsync(); JObject jsonObj = JObject.Parse(jsonFile); List <JToken> casts = jsonObj["cast"].Children().ToList(); List <CastModel> movieResults = new List <CastModel>(); foreach (JToken item in casts) { CastModel model = item.ToObject <CastModel>(); model.IsExist = myMovies.Contains(model.Id); model.IsExistWatched = myMoviesWatched.Contains(model.Id); movieResults.Add(model); } return(View(movieResults)); } } }
public ActionResult Edit(int BGId) { CastModel tbl = objCast.GetCasts().Where(p => p.CastId == BGId).FirstOrDefault(); return(Json(tbl, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Post() { string resultMessage = string.Empty; try { HttpResponseMessage result; List <TvShowModel> tvShowModelList = new List <TvShowModel>(); List <CastModel> castModelList = new List <CastModel>(); using (var client = new HttpClient()) { result = await client.GetAsync("http://api.tvmaze.com/shows"); if (result.IsSuccessStatusCode) { var tvShowResult = await result.Content.ReadAsStringAsync(); List <TvShowResponse> tvShowResponseList = JsonConvert.DeserializeObject <List <TvShowResponse> >(tvShowResult); foreach (var tvShowResponse in tvShowResponseList) { string castUrl = string.Format("http://api.tvmaze.com/shows/{0}/cast", tvShowResponse.id); result = await client.GetAsync(castUrl); TvShowModel tvShowModel = new TvShowModel(); tvShowModel.Id = tvShowResponse.id; tvShowModel.Name = tvShowResponse.name; if (result.IsSuccessStatusCode) { var castResult = await result.Content.ReadAsStringAsync(); List <CastResponse> castResponseList = JsonConvert.DeserializeObject <List <CastResponse> >(castResult); castModelList = new List <CastModel>(); foreach (var castResponse in castResponseList) { CastModel castModel = new CastModel(); castModel.Id = castResponse.Person.id; castModel.Name = castResponse.Person.name; castModel.Birthday = castResponse.Person.birthday; castModelList.Add(castModel); } tvShowModel.Cast = castModelList.OrderByDescending(x => x.Birthday).ToList(); } tvShowModelList.Add(tvShowModel); } } } _applicationService.InsertTvShowCollection(tvShowModelList); resultMessage = "Success"; } catch (Exception ex) { resultMessage = ex.Message; } return(Ok(resultMessage)); }