public async Task<IHttpActionResult> GetAll(int page = 1, int itemsPerPage = 20, string sortBy = "Name", bool reverse = false, string search = null)
        {
            try
            {
                var subscriptionList = new List<SubscriptionModel>();
                var subscriptions = _Uow._Subscription.GetAll(x => x.Active == true);

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    subscriptions = subscriptions.Where(x =>
                        x.Description.ToLower().Contains(search) ||
                        x.GatewayId.ToLower().Contains(search) ||
                        x.GatewayURL.ToLower().Contains(search) ||
                        x.Name.ToLower().Contains(search));
                }

                // sorting (done with the System.Linq.Dynamic library available on NuGet)
                subscriptions = subscriptions.OrderBy(sortBy + (reverse ? " descending" : ""));

                // paging
                var subscriptionsPaged = await subscriptions.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToListAsync();

                //Converting to modal object
                subscriptionsPaged.ForEach(x =>
                {
                    subscriptionList.Add(new SubscriptionModel
                    {
                        Description = x.Description,
                        EndDate = x.EndDate,
                        GatewayId = x.GatewayId,
                        Id = x.Id,
                        IsActiveSubscription = x.IsActiveSubscription,
                        Name = x.Name,
                        Price = x.Price,
                        StartDate = x.StartDate,
                        TimeDurationInDays = x.TimeDuration
                    });
                });

                // json result
                var json = new
                {
                    count = _Uow._Subscription.Count(),
                    data = subscriptionList
                };

                //await LogHelpers.SaveLog(_Uow, "View All Subscription", User.Identity.GetUserId());

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> GetAll(int page = 1, int itemsPerPage = 20, string sortBy = "DisplayOrder", bool reverse = false, string search = null)
        {
            try
            {
                var categories = _Uow._Categories.GetAll(x => x.Active == true);

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    categories = categories.Where(x =>
                        x.CategoryURL.ToLower().Contains(search) ||
                        x.SEOName.ToLower().Contains(search) ||
                        x.CategoryURL.ToLower().Contains(search) ||
                        x.Name.ToLower().Contains(search));
                }

                // sorting (done with the System.Linq.Dynamic library available on NuGet)
                categories = categories.OrderBy(sortBy + (reverse ? " descending" : ""));

                // paging
                var categoriesPaged = categories.Skip((page - 1) * itemsPerPage).Take(itemsPerPage);

                //await LogHelpers.SaveLog(_Uow, "View Categories", User.Identity.GetUserId());

                // json result
                var json = new
                {
                    count = _Uow._Categories.Count(),
                    data = categoriesPaged,
                };

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }
Exemplo n.º 3
0
        public IHttpActionResult GetAll(int page = 1, int itemsPerPage = 20, string sortBy = "Name", bool reverse = false, string search = null)
        {
            try
            {
                var videos = _Uow._Videos.GetAll(x => x.Active == true);

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    videos = videos.Where(x =>
                        x.Name.ToLower().Contains(search) ||
                        x.Description.ToLower().Contains(search));
                }

                // sorting (done with the System.Linq.Dynamic library available on NuGet)
                videos = videos.OrderBy(sortBy + (reverse ? " descending" : ""));

                // paging
                var videosPaged = videos.Skip((page - 1) * itemsPerPage).Take(itemsPerPage);

                // json result
                var json = new
                {
                    count = _Uow._Videos.Count(),
                    data = videosPaged,
                };

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }
Exemplo n.º 4
0
        public async Task<IHttpActionResult> GetContactRequestUsers(int page = 1, int itemsPerPage = 20)
        {
            try
            {
                var usersModelList = new List<SupportUsersModel>();
                var users = _Uow._SupportMessages.GetAll(x => x.Active == true && x.IsFromAdmin == false)
                    .OrderByDescending(x => x.MessageDatetime)
                    .Select(x => x.AspNetUser)
                    .Distinct();

                var totalContactedUsers = await users.CountAsync();

                var selectedUsers = await _Uow._SupportMessages.GetAll(x => x.Active == true && x.IsFromAdmin == false)
                    .OrderByDescending(x => x.MessageDatetime)
                    .Skip((page - 1) * itemsPerPage)
                    .Take(itemsPerPage)
                    .Select(x => x.AspNetUser)
                    .Distinct()
                    .ToListAsync();


                foreach (var user in selectedUsers)
                {
                    var supportUser = new SupportUsersModel();
                    supportUser.UserId = user.Id;
                    supportUser.UserName = user.UserName;
                    supportUser.FullName = user.FullName;
                    supportUser.TotalUnreadMessages = await _Uow._SupportMessages.CountAsync(x => (x.FromUserId == user.Id && x.IsRead == false));

                    usersModelList.Add(supportUser);
                }

                var json = new
                {
                    data = usersModelList,
                    count = totalContactedUsers
                };

                //await LogHelpers.SaveLog(_Uow, "View All Contacted Users", User.Identity.GetUserId());

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Exemplo n.º 5
0
        public async Task<IHttpActionResult> GetUserVideosHistory(int page = 1, int itemsPerPage = 20, string search = null)
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var _User = _Uow._Users.GetAll(x => x.Id == userId).FirstOrDefault();
                var videosList = new List<UserVideoModel>();

                var videos = _Uow._UserVideoHistory.GetAll(x => x.UserId == userId)
                    .OrderByDescending(x => x.WatchDateTime)
                    .Include(x => x.Video)
                    .Select(x => x.Video)
                    .Include(x => x.CategoryVideos)
                    .Include(x => x.CategoryVideos.Select(y => y.Category));

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    videos = videos.Where(x =>
                        x.Name.ToLower().Contains(search) ||
                        x.Description.ToLower().Contains(search));
                }

                int totalVideos = 0;
                totalVideos = await videos.CountAsync();

                //if (_User.IsFreeUser != null && _User.IsFreeUser.Value)
                //{
                //    videos = videos.Where(x => x.IsFreeVideo.Value);
                //    totalVideos = await videos.CountAsync(x => x.IsFreeVideo.Value);
                //}

                // paging
                var videosPaged = await videos.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToListAsync();

                videosPaged.ForEach(x =>
                {
                    var uvm = new UserVideoModel();
                    uvm.BackgroundColor = x.BackgroundColor;
                    uvm.DateLive = x.DateLive;
                    uvm.Duration = x.Duration;
                    uvm.Id = x.Id;
                    uvm.Name = x.Name;
                    uvm.ReleaseYear = x.ReleaseYear;
                    uvm.VzaarVideoId = x.StandardVideoId;
                    uvm.ThumbnailURL = x.ThumbnailURL;
                    uvm.IsFavoriteVideo = (x.UserFavoriteVideos != null && x.UserFavoriteVideos.Any(y => y.VideoId == x.Id));
                    if (x.CategoryVideos != null && x.CategoryVideos.Count > 0)
                    {
                        x.CategoryVideos.ToList().ForEach(y =>
                        {
                            uvm.Categories.Add(new UserCategoryModel
                            {
                                Id = y.Category.Id,
                                Name = y.Category.Name
                            });
                        });
                    }
                    videosList.Add(uvm);
                });

                //var count = await _Uow._UserVideoHistory.CountAsync(x => x.UserId == userId);

                // json result
                var json = new
                {
                    count = totalVideos,
                    data = videosList,
                };

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }
Exemplo n.º 6
0
        public async Task<IHttpActionResult> GetAll(int page = 1, int itemsPerPage = 20, string sortBy = "Name", bool reverse = false, string search = null)
        {
            try
            {
                var videosList = new List<VideoModel>();

                var videos = _Uow._Videos.GetAll(x => x.Active == true)
                    .Include(x => x.CategoryVideos);

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    videos = videos.Where(x =>
                        x.Name.ToLower().Contains(search) ||
                        x.Description.ToLower().Contains(search));
                }

                var totalVideos = await videos.CountAsync();

                // sorting (done with the System.Linq.Dynamic library available on NuGet)
                videos = videos.OrderBy(sortBy + (reverse ? " descending" : ""));

                // paging
                var videosPaged = videos.Skip((page - 1) * itemsPerPage).Take(itemsPerPage);

                foreach (var video in videosPaged)
                {
                    var model = new VideoModel();
                    model.Id = video.Id;
                    model.Name = video.Name;
                    model.Description = video.Description;
                    model.Duration = video.Duration;
                    model.ReleaseYear = video.ReleaseYear;
                    if (video.DateLive != null)
                    {
                        model.DateLive = video.DateLive;
                    }
                    model.BackgroundColor = video.BackgroundColor;
                    model.IsEnabled = video.IsEnabled;
                    model.StandardVideoId = video.StandardVideoId;
                    model.FastVideoId = video.StandardVideoId;
                    if (video.CategoryVideos != null && video.CategoryVideos.Count > 0)
                    {
                        foreach (var item in video.CategoryVideos)
                        {
                            model.Categories.Add(item.CategoryId.Value);
                        }
                    }
                    videosList.Add(model);
                }

                // json result
                var json = new
                {
                    count = totalVideos,
                    data = videosList,
                };

                //await LogHelpers.SaveLog(_Uow, "Check All Videos", User.Identity.GetUserId());

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }
Exemplo n.º 7
0
        public async Task<IHttpActionResult> AddVideo(VideoModel model)
        {
            try
            {
                var video = new DrNajeeb.EF.Video();
                video.Name = model.Name;
                video.Description = model.Description;
                video.Duration = model.Duration;
                video.ReleaseYear = model.ReleaseYear;
                if (video.DateLive != null)
                {
                    video.DateLive = model.DateLive.Value;
                }
                else
                {
                    video.DateLive = DateTime.UtcNow;
                }
                video.BackgroundColor = model.BackgroundColor;
                video.IsEnabled = model.IsEnabled;
                video.StandardVideoId = model.StandardVideoId;
                video.FastVideoId = model.FastVideoId;
                video.Active = true;
                video.CreatedOn = DateTime.UtcNow;
                video.IsFreeVideo = model.IsFreeVideo;
                video.ThumbnailURL = @"http://view.vzaar.com/" + model.StandardVideoId + "/thumb";

                if (model.Categories != null && model.Categories.Count > 0)
                {
                    foreach (var item in model.Categories)
                    {
                        video.CategoryVideos.Add(new EF.CategoryVideo
                        {
                            CategoryId = item,
                            VideoId = video.Id,
                            CreatedOn = DateTime.UtcNow,
                        });
                    }
                }

                //todo : add useid in createdby

                _Uow._Videos.Add(video);
                await _Uow.CommitAsync();
                var json = new
                {
                    Id = video.Id,
                    Name = video.Name
                };

                await LogHelpers.SaveLog(_Uow, "Add Video : "+video.Name, User.Identity.GetUserId());

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Exemplo n.º 8
0
        public async Task<IHttpActionResult> GetLastWatchedVideo()
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var lastWatchedVideo = await _Uow._UserVideoHistory.GetAll(x => x.UserId == userId)
                    .OrderByDescending(x => x.WatchDateTime)
                    .Include(x => x.Video)
                    .FirstOrDefaultAsync();

                if (lastWatchedVideo == null)
                {
                    return NotFound();
                }

                var json = new
                {
                    videoId=lastWatchedVideo.VideoId,
                    name=lastWatchedVideo.Video.Name,
                    lastSeekTime=lastWatchedVideo.LastSeekTime.GetValueOrDefault()
                };

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Exemplo n.º 9
0
        public async Task<IHttpActionResult> GetAllTimeTopVideos()
        {
            try
            {
                var videosList = new List<UserVideoModel>();

                var videos = await _Uow._Videos.GetAll(x => x.Active == true)
                    .Include(x => x.UserVideoHistories)
                    .Select(x => new
                    {
                        video = x,
                        totalViews = x.UserVideoHistories.Count
                    })
                    .OrderByDescending(x => x.totalViews)
                    .Select(x => x.video)
                    .Include(x=>x.CategoryVideos)
                    .Include(x => x.CategoryVideos.Select(y => y.Category))
                    .Take(5)
                    .ToListAsync();

                videos.ForEach(x =>
                {
                    var uvm = new UserVideoModel();
                    uvm.BackgroundColor = x.BackgroundColor;
                    uvm.DateLive = x.DateLive;
                    uvm.Duration = x.Duration;
                    uvm.Id = x.Id;
                    uvm.Name = x.Name;
                    uvm.ReleaseYear = x.ReleaseYear;
                    uvm.VzaarVideoId = x.StandardVideoId;
                    uvm.ThumbnailURL = x.ThumbnailURL;
                    if (x.CategoryVideos != null && x.CategoryVideos.Count > 0)
                    {
                        x.CategoryVideos.ToList().ForEach(y =>
                        {
                            uvm.Categories.Add(new UserCategoryModel
                            {
                                Id = y.Category.Id,
                                Name = y.Category.Name
                            });
                        });
                    }
                    videosList.Add(uvm);
                });

                // json result
                var json = new
                {
                    count = 5,
                    data = videosList,
                };

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Exemplo n.º 10
0
        public async Task<IHttpActionResult> CheckValidity(string id)
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var user = await _Uow._Users.GetAll(x => x.Id == userId).FirstOrDefaultAsync();

                var loggedInUsers = _Uow._LoggedInTracking.GetAll(x => x.UserId == userId).OrderBy(x => x.DateTimeLoggedIn);

                if (!loggedInUsers.Any(x => x.Token == id))
                {
                    var json = new
                    {
                        Result = false,
                    };
                    return Ok(json);
                }

                if (loggedInUsers.Count() > user.NoOfConcurentViews)
                {
                    var toDelete = await loggedInUsers.FirstAsync();
                    _Uow._LoggedInTracking.Delete(toDelete);
                    await _Uow.CommitAsync();
                    var json = new
                    {
                        Result = true,
                    };
                    return Ok(json);
                }

                var jsonResult = new
                {
                    Result = true,
                };
                return Ok(jsonResult);
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }
Exemplo n.º 11
0
        public async Task<IHttpActionResult> GetAll(int page = 1, int itemsPerPage = 20, string sortBy = "CreatedOn", bool reverse = true, string search = null)
        {
            try
            {
                var usersList = new List<UserModel>();

                var users = _Uow._Users.GetAll(x => x.Active == true)
                    .Include(x => x.Country)
                    .Include(x => x.Subscription)
                    .Include(x => x.AspNetRoles)
                    .Include(x => x.IpAddressFilters);

                // searching
                if (!string.IsNullOrWhiteSpace(search))
                {
                    search = search.ToLower();
                    users = users.Where(x =>
                        x.FullName.ToLower().Contains(search) ||
                        x.UserName.ToLower().Contains(search) ||
                        x.Email.ToLower().Contains(search));
                }

                // sorting (done with the System.Linq.Dynamic library available on NuGet)
                users = users.OrderBy(sortBy + (reverse ? " descending" : ""));

                // paging
                var usersPaged = await users.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToListAsync();

                foreach (var item in usersPaged)
                {
                    var usermodel = new UserModel();
                    usermodel.CountryID = item.CountryId;
                    usermodel.EmailAddress = item.Email;
                    usermodel.FullName = item.FullName;
                    usermodel.IsActiveUser = item.IsActiveUSer;
                    usermodel.Id = item.Id;
                    usermodel.IsFilterByIP = item.IsFilterByIP;
                    usermodel.NoOfConcurrentViews = item.NoOfConcurentViews;
                    usermodel.SubscriptionID = item.SubscriptionId;
                    if (item.Country != null)
                    {
                        usermodel.Country.CountryCode = item.Country.CountryCode;
                        usermodel.Country.FlagImage = item.Country.FlagImage;
                        usermodel.Country.Name = item.Country.Name;
                    }
                    if (item.AspNetRoles != null)
                    {
                        foreach (var role in item.AspNetRoles)
                        {
                            usermodel.RolesModel.Add(new RoleModel
                            {
                                Id = role.Id,
                                Name = role.Name
                            });
                        }
                    }
                    if (item.Subscription != null)
                    {
                        usermodel.Subscription.Name = item.Subscription.Name;
                        usermodel.Subscription.Id = item.Subscription.Id;
                    }
                    if (item.IsFilterByIP)
                    {
                        if (item.IpAddressFilters != null)
                        {
                            usermodel.FilteredIPs = new List<string>();
                            foreach (var ipAddress in item.IpAddressFilters)
                            {
                                usermodel.FilteredIPs.Add(ipAddress.IpAddress);
                            }
                        }
                    }
                    usersList.Add(usermodel);
                }

                // json result
                var json = new
                {
                    count = _Uow._Users.Count(),
                    data = usersList,
                };

                //await LogHelpers.SaveLog(_Uow, "Check All  Users", User.Identity.GetUserId());

                return Ok(json);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

        }