Example #1
0
        public async Task <List <ImgModel> > SearchImgByUser(string userId)
        {
            List <ImgModel> ls = new List <ImgModel>();

            try
            {
                var repo = uow.ImageRepo();
                foreach (var item in await repo.GetEntities())
                {
                    if (item.UploadedBy == userId.Split('#')[1])
                    {
                        ls.Add(new ImgModel()
                        {
                            CategoryName = item.Cat.CatName,
                            ImgId        = item.ImgId,
                            ImgName      = item.ImgName,
                            ImgURL       = PathConfig.IMG_URL + item.FileName,
                            UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(item.UploadedDate)).ToString(),
                            LikeCount    = await GetLikes(item.ImgId),
                            UploadBy     = item.UploadedBy,
                            Views        = item.View
                        });
                    }
                }
                return(ls);
            }
            catch (Exception)
            {
                return(ls);
            }
        }
Example #2
0
        public async Task <List <ImgModel> > GetImg()
        {
            try
            {
                var repo = uow.ImageRepo();
                var rs   = await repo.GetEntities();

                List <ImgModel> ls = new List <ImgModel>();
                foreach (var item in rs)
                {
                    if (item.IsValid != false)
                    {
                        ls.Add(new ImgModel
                        {
                            CategoryName = item.Cat.CatName,
                            UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(item.UploadedDate)).ToString(),
                            ImgName      = item.ImgName,
                            ImgURL       = PathConfig.IMG_URL + item.FileName,
                            LikeCount    = await GetLikes(item.ImgId),
                            UploadBy     = item.UploadedBy ?? "",
                            Views        = item.View,
                            ImgId        = item.ImgId
                        });
                    }
                }
                return(ls);
            }
            catch
            {
                return(null);
            }
        }
Example #3
0
 public async Task <List <ImgModel> > SearchImg(string content)
 {
     try
     {
         var             repo   = uow.ImageRepo();
         List <ImgModel> models = new List <ImgModel>();
         foreach (var item in await repo.GetEntities())
         {
             if (item.ImgName.ToLower().StartsWith(content) || item.ImgName.ToLower().Contains(content))
             {
                 models.Add(new ImgModel()
                 {
                     CategoryName = item.Cat.CatName,
                     ImgId        = item.ImgId,
                     ImgName      = item.ImgName,
                     LikeCount    = await GetLikes(item.ImgId),
                     ImgURL       = PathConfig.IMG_URL + item.FileName,
                     UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(item.UploadedDate)).ToString(),
                     UploadBy     = item.UploadedBy
                 });
             }
         }
         return(models);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #4
0
        public async Task <ImgModel> GetImgById(string id)
        {
            var repo = uow.ImageRepo();

            try
            {
                var filter = Builders <tblImg> .Filter.Eq(x => x.ImgId, id);

                var rs = await repo.CustomQuery(filter);

                return(new ImgModel()
                {
                    CategoryName = rs.FirstOrDefault().Cat.CatName,
                    ImgId = rs.FirstOrDefault().ImgId,
                    ImgName = rs.FirstOrDefault().ImgName,
                    ImgURL = PathConfig.IMG_URL + rs.FirstOrDefault().FileName,
                    UploadBy = rs.FirstOrDefault().UploadedBy,
                    UploadDate = TimeStamp.GetDateFromUnix(long.Parse(rs.FirstOrDefault().UploadedDate)).ToString(),
                    LikeCount = await GetLikes(rs.FirstOrDefault().ImgId),
                    Views = rs.FirstOrDefault().View
                });
            }
            catch
            {
                return(new ImgModel());
            }
        }
Example #5
0
 public async Task <List <ImgModel> > GetPendingImgs()
 {
     try
     {
         var             repo = uow.ImageRepo();
         List <ImgModel> ls   = new List <ImgModel>();
         foreach (var item in await repo.GetEntities())
         {
             if (!item.IsValid)
             {
                 ls.Add(new ImgModel()
                 {
                     CategoryName = item.Cat.CatName,
                     ImgId        = item.ImgId,
                     ImgURL       = PathConfig.IMG_URL + item.FileName,
                     ImgName      = item.ImgName,
                     UploadBy     = item.UploadedBy ?? "",
                     UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(item.UploadedDate)).ToString()
                 });
             }
         }
         return(ls);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #6
0
 public async Task <List <ImgModel> > GetImgByCat(string catName)
 {
     try
     {
         var             imgRepo = uow.ImageRepo();
         List <ImgModel> ls      = new List <ImgModel>();
         foreach (var img in await imgRepo.GetEntities())
         {
             if (img.Cat.CatName == catName && img.IsValid)
             {
                 ls.Add(new ImgModel()
                 {
                     CategoryName = img.Cat.CatName,
                     ImgName      = img.ImgName,
                     ImgURL       = PathConfig.IMG_URL + img.FileName,
                     LikeCount    = await GetLikes(img.ImgId),
                     UploadBy     = img.UploadedBy ?? "",
                     UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(img.UploadedDate)).ToString(),
                     Views        = img.View,
                     ImgId        = img.ImgId
                 });
             }
         }
         return(ls);
     }
     catch
     {
         return(null);
     }
 }
Example #7
0
        public async Task <List <ImgModel> > GetUserFavoriteImg(string userName)
        {
            try
            {
                List <ImgModel> ls       = new List <ImgModel>();
                var             imgRepo  = uow.ImageRepo();
                var             rateRepo = uow.ImgRatingRepo();
                var             lsImgs   = await imgRepo.GetEntities();

                var rateImgs = await rateRepo.GetEntities();

                var query = from i in lsImgs
                            join r in rateImgs
                            on i.ImgId equals r.ImgId
                            select new
                {
                    i.ImgName,
                    i.UploadedDate,
                    i.UploadedBy,
                    r.IsLike,
                    i.ImgId,
                    i.View,
                    i.Cat,
                    i.FileName
                };
                foreach (var item in query)
                {
                    if (item.IsLike == true)
                    {
                        ls.Add(new ImgModel()
                        {
                            UploadDate   = TimeStamp.GetDateFromUnix(long.Parse(item.UploadedDate)).ToString(),
                            UploadBy     = item.UploadedBy,
                            CategoryName = item.Cat.CatName,
                            ImgName      = item.ImgName,
                            ImgURL       = PathConfig.IMG_URL + item.FileName,
                            LikeCount    = await GetLikes(item.ImgId),
                            Views        = item.View,
                            ImgId        = item.ImgId
                        });
                    }
                }
                return(ls);
            }
            catch
            {
                return(null);
            }
        }