public async Task<IHttpActionResult> GetSingle(int Id)
        {
            try
            {
                var video = await _Uow._Videos.GetByIdAsync(Id);
                if (video == null)
                {
                    return NotFound();
                }

                var model = new VideoModel();
                model.Name = video.Name;
                model.Description = video.Description;
                model.Duration = video.Duration;
                model.ReleaseYear = video.ReleaseYear;
                if (model.DateLive != null)
                {
                    model.DateLive = video.DateLive;
                }
                model.BackgroundColor = video.BackgroundColor;
                model.IsEnabled = video.IsEnabled;
                model.StandardVideoId = video.StandardVideoId;
                model.FastVideoId = video.StandardVideoId;

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

                return Ok(model);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
        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);
            }

        }
        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);
            }
        }
        public async Task<IHttpActionResult> UpdateVideo(VideoModel model)
        {
            try
            {
                var video = await _Uow._Videos.GetByIdAsync(model.Id);
                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;
                }
                video.BackgroundColor = model.BackgroundColor;
                video.IsEnabled = model.IsEnabled;
                video.StandardVideoId = model.StandardVideoId;
                video.FastVideoId = model.StandardVideoId;
                video.IsFreeVideo = model.IsFreeVideo ?? false;
                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
                        });
                    }
                }

                var categoryVideos = _Uow._CategoryVideos.GetAll(x => x.VideoId == model.Id);
                foreach (var item in categoryVideos)
                {
                    _Uow._CategoryVideos.Delete(item);
                }
                video.UpdatedBy = User.Identity.GetUserId();

                _Uow._Videos.Update(video);
                await _Uow.CommitAsync();

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

                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
        public async Task<IHttpActionResult> GetFreeVideosForSorting()
        {
            try
            {
                var videosList = new List<VideoModel>();

                var videos = await _Uow._Videos
                    .GetAll(x => x.IsFreeVideo == true)
                    .OrderBy(x => x.FreeVideoOrder)
                    .ToListAsync();

                foreach (var video in videos)
                {
                    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;
                    videosList.Add(model);
                }

                //await LogHelpers.SaveLog(_Uow, "Get Videos Of Category For Sorting", User.Identity.GetUserId());

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

        }