public ServiceResponse <WatchHistoryDto> Update(int id, int userId, WatchHistoryDto model) { var response = new ServiceResponse <WatchHistoryDto>(); try { model.UserId = userId; if (model.Id == id) { var item = new WatchHistory(); item.UserId = userId; item.Id = model.Id; item.CourseId = model.CourseId; _repository.Update(item); response.IsSuccessful = true; } } catch (Exception) { response.ExceptionMessage = ErrorCodes.BilinmeyenHata.Text; response.IsSuccessful = false; } return(response); }
public ActionResult Post([FromBody] SeenModel std) { WatchHistory wh = new WatchHistory(); wh.AdId = std.adId; wh.UserId = std.userId; wh.Seen = std.seen; wh.Liked = std.liked; db.WatchHistory.Add(wh); db.SaveChanges(); return(Ok(new { status = true, message = "History Posted Successfully" })); }
public ActionResult Post([FromBody] HistoryModel std) { if (std.userId > 0 && std.adId > 0) { WatchHistory wh = new WatchHistory(); wh.UserId = std.userId; wh.AdId = std.adId; wh.Seen = std.seen; wh.Liked = std.liked; db.WatchHistory.Add(wh); db.SaveChanges(); return(Ok(new { status = true, message = "History Posted Successfully" })); } return(BadRequest(new { status = false, message = "Error! History wasn't posted" })); }
public dynamic AddWAtchHistory(Dictionary <string, object> dictionary) { WatchHistory watchHistory = new WatchHistory(); watchHistory.VideoID = Convert.ToInt32(dictionary["id"].ToString()); watchHistory.CategoryID = Convert.ToInt32(dictionary["category"].ToString()); watchHistory.UserId = dictionary["userId"].ToString(); watchHistory.WatchDate = DateTime.Now; repository.WatchHistories.Add(watchHistory); var result = repository.SaveChanges(); if (result > 0) { return(true); } return(false); }
public async Task Delete_Watch_History_Success() { var watchHistory = new WatchHistory { MediaId = "foo", ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("hello", "world")) }; _context.WatchHistories.Add(watchHistory); _context.SaveChanges(); var result = await _controller.DeleteWatchHistory(watchHistory.Id); Assert.Equal(watchHistory, result.Value); Assert.Empty(_context.WatchHistories.ToList()); }
public async Task <IActionResult> PostWatchHistory(string mediaId, JObject json) { var media = await _context.Medias.FindAsync(mediaId); if (media == null || json == null) { return(BadRequest()); } var user = await _userUtils.GetUser(User); if (user != null) { var watchHistory = await _context.WatchHistories .Where(w => w.MediaId == mediaId && w.ApplicationUserId == user.Id) .FirstOrDefaultAsync(); if (watchHistory == null) { watchHistory = new WatchHistory { ApplicationUserId = user.Id, MediaId = mediaId, Json = json }; await _context.WatchHistories.AddAsync(watchHistory); } else { watchHistory.Json = json; _context.Entry(watchHistory).State = EntityState.Modified; } await _context.SaveChangesAsync(); } else { return(Unauthorized()); } return(NoContent()); }
public async Task Get_All_Watch_History_For_User_Filters_Duplicates() { var media = new Media { Id = "media", Name = "exampleMedia" }; var wh1 = new WatchHistory { MediaId = media.Id, ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("hello", "world")), }; var wh2 = new WatchHistory { MediaId = media.Id, ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("bar", "baz")) }; _context.Users.Add(new ApplicationUser { Id = TestGlobals.TEST_USER_ID }); _context.Medias.Add(media); _context.WatchHistories.Add(wh1); _context.SaveChanges(); // save changes twice so wh2 has LastUpdatedAt later than wh1's LastUpdatedAt _context.WatchHistories.Add(wh2); _context.SaveChanges(); var result = await _controller.GetAllWatchHistoryForUser(); Assert.Single(result.Value); Assert.Equal(media.Id, result.Value.ElementAt(0).Id); Assert.Equal(media.Name, result.Value.ElementAt(0).Name); Assert.Equal(wh2.Json, result.Value.ElementAt(0).WatchHistory.Json); Assert.Equal(wh2, result.Value.ElementAt(0).WatchHistory); }
public ServiceResponse <WatchHistoryDto> Insert(int userId, WatchHistoryDto model) { var response = new ServiceResponse <WatchHistoryDto>(); try { var item = new WatchHistory(); item.UserId = userId; item.CourseId = model.CourseId; item.DateAdded = DateTime.Now; _repository.Insert(item); response.IsSuccessful = true; } catch (Exception) { response.ExceptionMessage = ErrorCodes.BilinmeyenHata.Text; response.IsSuccessful = false; } return(response); }
public async Task Get_Watch_History_Success() { var mediaId = "media"; var watchHistory = new WatchHistory { MediaId = mediaId, ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("hello", "world")) }; _context.Medias.Add(new Media { Id = mediaId }); _context.Users.Add(new ApplicationUser { Id = TestGlobals.TEST_USER_ID }); _context.WatchHistories.Add(watchHistory); _context.SaveChanges(); var result = await _controller.GetWatchHistory(mediaId); Assert.Equal(watchHistory, result.Value); }
public async Task Get_All_Watch_History_For_User_Success() { var medias = new List <Media>() { new Media { Id = "media", Name = "exampleMedia", PlaylistId = "none", JsonMetadata = new JObject(new JProperty("foo", "bar")), SourceType = SourceType.Kaltura, Video = new Video { Duration = TimeSpan.FromSeconds(13) } }, new Media { Id = "media2", Name = "exampleMedia2", PlaylistId = "none2", JsonMetadata = new JObject(new JProperty("foo", "baz")), SourceType = SourceType.Box } }; var wh1 = new WatchHistory { MediaId = medias[0].Id, ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("hello", "world")), }; var wh2 = new WatchHistory { MediaId = medias[1].Id, ApplicationUserId = TestGlobals.TEST_USER_ID, Json = new JObject(new JProperty("bar", "baz")) }; var shouldBeIgnored = new List <WatchHistory>() { new WatchHistory { MediaId = medias[0].Id, ApplicationUserId = "other_user" }, new WatchHistory { MediaId = "non_existing", ApplicationUserId = TestGlobals.TEST_USER_ID }, }; _context.Users.Add(new ApplicationUser { Id = TestGlobals.TEST_USER_ID }); _context.Medias.AddRange(medias); _context.WatchHistories.Add(wh1); _context.SaveChanges(); // save changes twice so wh2 has LastUpdatedAt later than wh1's LastUpdatedAt _context.WatchHistories.Add(wh2); _context.WatchHistories.AddRange(shouldBeIgnored); _context.SaveChanges(); var result = await _controller.GetAllWatchHistoryForUser(); Assert.Equal(2, result.Value.Count()); Assert.Equal(medias[1].Name, result.Value.ElementAt(0).Name); Assert.Equal(medias[1].PlaylistId, result.Value.ElementAt(0).PlaylistId); Assert.Equal(medias[1].JsonMetadata, result.Value.ElementAt(0).JsonMetadata); Assert.Equal(medias[1].SourceType, result.Value.ElementAt(0).SourceType); Assert.Equal(wh2, result.Value.ElementAt(0).WatchHistory); Assert.Equal(medias[0].Name, result.Value.ElementAt(1).Name); Assert.Equal(medias[0].PlaylistId, result.Value.ElementAt(1).PlaylistId); Assert.Equal(medias[0].JsonMetadata, result.Value.ElementAt(1).JsonMetadata); Assert.Equal(medias[0].SourceType, result.Value.ElementAt(1).SourceType); Assert.Equal(medias[0].Video.Duration, result.Value.ElementAt(1).Duration); Assert.Equal(wh1, result.Value.ElementAt(1).WatchHistory); }