/// <summary> /// Creating a session guid that allows users to play content /// </summary> /// <param name="data">DatabaseUserModels</param> /// <returns>string</returns> public static async Task <Object> Session <T>(DatabaseUserModels data) { bool isGuest = false; Guid g1; if (data.user_id.Length > 30) { var s0 = await db.Session_Play.Where(x => x.movie_id == data.movie_id && x.user_id == data.user_id).FirstOrDefaultAsync(); if (s0 != null) { if (s0.movie_id != "" && s0.session_id != "" && s0.session_date < DateTime.Now && s0.user_id != "") { db.Session_Play.Remove(s0); await db.SaveChangesAsync(); } } isGuest = false; g1 = new Guid(data.user_id); } else { isGuest = true; MD5 md5Hasher = MD5.Create(); g1 = new Guid(md5Hasher.ComputeHash(Encoding.Default.GetBytes(DateTime.Now.ToString()))); } Guid g2 = new Guid(data.movie_id); var result = g1.GetHashCode() ^ g2.GetHashCode() + DateTime.Now.GetHashCode(); List <CustomClasses.Random.values> v = new List <CustomClasses.Random.values>(); if (isGuest) { var s = new Session_Guest() { session_date = DateTime.Now, session_id = Movie.Create.Guid(result.ToString()).ToString(), movie_id = data.movie_id, }; db.Session_Guest.Add(s); await db.SaveChangesAsync(); return(s); } else { var s = new Session_Play() { session_date = DateTime.Now, session_id = Movie.Create.Guid(result.ToString()).ToString(), movie_id = data.movie_id, user_id = data.user_id }; db.Session_Play.Add(s); await db.SaveChangesAsync(); return(s); } }
public async Task <IHttpActionResult> GetSession([FromBody] DatabaseUserModels data) { var s = await Database.User.Get.Session(data); if (s.session_id == "" || s == null) { return(NotFound()); } return(Ok(s.session_id)); }
public async Task <IHttpActionResult> GetMovie([FromBody] DatabaseUserModels data) { var movie = await Database.Movie.Get.ByModel(data); if (movie == null) { return(NotFound()); } CustomClasses.MovieSession a = new CustomClasses.MovieSession() { movieData = movie }; if (data.user_id.Length < 20) { //user is a guest await History.Create(History.Type.User, new History_User() { user_action = "Guest | Auth to watch Movie -> " + movie.Movie_Info.title, user_datetime = DateTime.Now, user_id = data.user_id, user_movie = movie.guid, user_type = "Status -> AuthGuest -> View Content" }); a.sessionGuest = (Session_Guest)await Database.User.Create.Session <Session_Guest>(data); } else { //user is registered var u = await Database.User.Get.ByGuid(data.user_id); if (u != null) { await History.Create(History.Type.User, new History_User() { user_action = "User -> " + u.display_name + " | Auth -> " + data.user_id + " | Movie -> " + movie.Movie_Info.title, user_datetime = DateTime.Now, user_id = data.user_id, user_movie = movie.guid, user_type = "Status -> AuthRegistered -> View Content" }); a.sessionPlay = (Session_Play)await Database.User.Create.Session <Session_Play>(data); } } return(Ok(a)); }
/// <summary> /// Retrieve movie from db and increase the view counter /// </summary> /// <param name="data">DatabaseUserModels</param> /// <returns>MovieData</returns> public static async Task <Movie_Data> ByModel(DatabaseUserModels data) { var user = await db.User_Info.Where(x => x.unique_id == data.user_id).FirstOrDefaultAsync(); var movie = await db.Movie_Data.Where(x => x.guid == data.movie_id).FirstOrDefaultAsync(); if (user != null) { await History.Create(History.Type.User, new History_User() { user_action = "User | Requesting content-> " + data.movie_id + " | Username -> " + user.username + ", UserId-> " + user.unique_id, user_datetime = DateTime.Now, user_movie = movie.Movie_Info.title, user_type = "User Requesting content from Movie.Get.ByModel()" }); } return(movie); }
/// <summary> /// Retrieve a session from database /// </summary> /// <param name="data">DatabaseUserModels</param> /// <returns>SessionPlay</returns> public static async Task <Session_Play> Session(DatabaseUserModels data) { return(await db.Session_Play.Where(x => x.movie_id == data.movie_id && x.user_id == data.user_id).FirstOrDefaultAsync()); }