예제 #1
0
        public bool FollowUserDL(int personID, int follow)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var person         = context.Person.Find(personID);
                    var personToFollow = context.Person.Find(follow);

                    if (context.Follow.Any(f => f.ID_Person == personID && f.ID_PersonFollowed == follow))
                    {
                        Follow followToRemove = context.Follow.Where(f => f.ID_Person == personID && f.ID_PersonFollowed == follow).FirstOrDefault();
                        context.Follow.Remove(followToRemove);
                        context.SaveChanges();
                        return(false);
                    }

                    else
                    {
                        context.Follow.Add(new Follow()
                        {
                            ID_Person = personID, ID_PersonFollowed = follow, DateOfAction = DateTime.Now
                        });
                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
예제 #2
0
        public ProfileDetailsDTO ChangeProfileDetailsDL(ProfileDetailsDTO data, int personID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var person = context.Person.Where(p => p.PersonID == personID).First();
                    person.PersonalDescription = data.PersonalDescription;
                    person.WebSiteURL          = data.WebSiteURL;

                    if (string.IsNullOrWhiteSpace(data.Year) && string.IsNullOrWhiteSpace(data.Month) && string.IsNullOrWhiteSpace(data.Day))
                    {
                        person.Birthdate = null;
                        data.Birthdate   = null;
                    }
                    else
                    {
                        person.Birthdate = new DateTime(Convert.ToInt32(data.Year), Convert.ToInt32(data.Month), Convert.ToInt32(data.Day));
                        data.Birthdate   = BirthDatePhrase(person.Birthdate);
                    }
                    context.SaveChanges();

                    return(data);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #3
0
        public bool RegisterDL(string userName, string email, string password)
        {
            if (!AccountExists(userName, email))
            {
                using (var context = new MiniBirdEntities())
                {
                    var newPerson = new Person()
                    {
                        UserName         = "******" + userName,
                        Email            = email,
                        NickName         = userName,
                        Password         = password,
                        DarkMode         = false,
                        RegistrationDate = DateTime.Now
                    };
                    context.Person.Add(newPerson);
                    context.SaveChanges();
                    newPerson.PersonCryptID = EncryptToSHA256(newPerson.PersonID);
                    context.SaveChanges();

                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        public FullViewPostDTO ViewPostCollectionDataDL(int postID)
        {
            try
            {
                var         fullViewPost = new FullViewPostDTO();
                ViewPostDTO viewPost     = this.ViewPostAjaxCollectionDataDL(postID);
                fullViewPost.PostSection   = viewPost.PostSection;
                fullViewPost.RepliesToPost = viewPost.RepliesToPost;

                using (var context = new MiniBirdEntities())
                {
                    var person = context.Person.Find(fullViewPost.PostSection.CreatedBy);
                    fullViewPost.ProfileInformation.Birthdate           = (person.Birthdate.HasValue) ? BirthDatePhrase(person.Birthdate) : "";
                    fullViewPost.ProfileInformation.NickName            = person.NickName;
                    fullViewPost.ProfileInformation.PersonalDescription = person.PersonalDescription;
                    fullViewPost.ProfileInformation.ProfileAvatar       = (person.ProfileAvatar != null) ? ByteArrayToBase64(person.ProfileAvatar, person.ProfileAvatar_MimeType) : defaultAvatar;
                    fullViewPost.ProfileInformation.ProfileHeader       = (person.ProfileHeader != null) ? ByteArrayToBase64(person.ProfileHeader, person.ProfileHeader_MimeType) : defaultHeader;
                    fullViewPost.ProfileInformation.RegistrationDate    = person.RegistrationDate;
                    fullViewPost.ProfileInformation.UserName            = person.UserName;
                    fullViewPost.ProfileInformation.WebSiteURL          = person.WebSiteURL;

                    return(fullViewPost);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #5
0
        public SessionInformation CreateSessionDL(string emailOrUsername)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var person = context.Person.Where(p => p.UserName == "@" + emailOrUsername || p.Email == emailOrUsername).First();

                    return(new SessionInformation()
                    {
                        PersonID = person.PersonID,
                        UserName = person.UserName,
                        Email = person.Email,
                        NickName = person.NickName,
                        ProfileAvatar = (person.ProfileAvatar != null) ? ByteArrayToBase64(person.ProfileAvatar, person.ProfileAvatar_MimeType) : defaultAvatar,
                        ProfileHeader = (person.ProfileHeader != null) ? ByteArrayToBase64(person.ProfileHeader, person.ProfileHeader_MimeType) : defaultHeader,
                        Theme = (person.DarkMode == true) ? Theme.Dark : Theme.Light
                    });
                }
            }
            catch
            {
                throw;
            }
        }
예제 #6
0
 public void AddProfileToListsDL(List <CheckboxListsDTO> model, int currentProfileID)
 {
     using (var context = new MiniBirdEntities())
     {
         foreach (var list in model)
         {
             if (context.UserToList.Any(ul => ul.ID_List == list.MyListID && ul.ID_Person == currentProfileID) != list.PersonalList)
             {
                 if (list.PersonalList)
                 {
                     context.UserToList.Add(new UserToList()
                     {
                         ID_List = list.MyListID, ID_Person = currentProfileID, DateOfAggregate = DateTime.Now
                     });
                     context.SaveChanges();
                 }
                 else
                 {
                     context.UserToList.Remove(context.UserToList.Find(list.MyListID, currentProfileID));
                     context.SaveChanges();
                 }
             }
         }
     }
 }
예제 #7
0
 private bool AccountExists(string userName, string email)
 {
     using (var context = new MiniBirdEntities())
     {
         return(context.Person.Any(p => p.Email == email || p.UserName == userName));
     }
 }
예제 #8
0
 public bool UserNameExistsDL(string username)
 {
     using (var context = new MiniBirdEntities())
     {
         return(context.Person.Any(p => p.UserName == username));
     }
 }
예제 #9
0
        public SessionInformation CreateSessionFromCookieDL(string hash)
        {
            try
            {
                const string defaultAvatar = "/Content/images/defaultAvatar.png";
                const string defaultHeader = "/Content/images/defaultHeader.jpg";

                using (var context = new MiniBirdEntities())
                {
                    var person = context.Person.Where(p => p.PersonCryptID == hash).First();

                    return(new SessionInformation()
                    {
                        PersonID = person.PersonID,
                        UserName = person.UserName,
                        Email = person.Email,
                        NickName = person.NickName,
                        ProfileAvatar = (person.ProfileAvatar != null) ? ByteArrayToBase64(person.ProfileAvatar, person.ProfileAvatar_MimeType) : defaultAvatar,
                        ProfileHeader = (person.ProfileHeader != null) ? ByteArrayToBase64(person.ProfileHeader, person.ProfileHeader_MimeType) : defaultHeader
                    });
                }
            }
            catch
            {
                throw;
            }
        }
예제 #10
0
        public ProfileDetailsDTO ChangeProfileDetailsDL(int personID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var person            = context.Person.Where(p => p.PersonID == personID).First();
                    var profileDetailsDTO = new ProfileDetailsDTO();
                    profileDetailsDTO.PersonalDescription = person.PersonalDescription;
                    profileDetailsDTO.WebSiteURL          = person.WebSiteURL;

                    if (person.Birthdate.HasValue)
                    {
                        profileDetailsDTO.Birthdate = BirthDatePhrase(person.Birthdate);
                        profileDetailsDTO.Day       = person.Birthdate.Value.Day.ToString();
                        profileDetailsDTO.Month     = person.Birthdate.Value.Month.ToString();
                        profileDetailsDTO.Year      = person.Birthdate.Value.Year.ToString();
                    }

                    return(profileDetailsDTO);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #11
0
        public string ChangeAvatarDL(HttpPostedFile img, int personID)
        {
            using (var context = new MiniBirdEntities())
            {
                var person    = context.Person.Where(p => p.PersonID == personID).First();
                var newAvatar = PostedFileToByteArray(img);
                person.ProfileAvatar          = newAvatar;
                person.ProfileAvatar_MimeType = img.ContentType;
                context.SaveChanges();

                return(ByteArrayToBase64(newAvatar, img.ContentType));
            }
        }
예제 #12
0
        private List <PostSectionDTO> FillPostSection(List <Post> posts, int currentPersonID, List <RePost> reposts)
        {
            using (var context = new MiniBirdEntities())
            {
                List <PostSectionDTO> postSection = new List <PostSectionDTO>();

                foreach (var post in posts)
                {
                    var createdBy = context.Person.Find(post.ID_Person);

                    postSection.Add(new PostSectionDTO()
                    {
                        PostID          = post.PostID,
                        Comment         = post.Comment,
                        GIFImage        = post.GIFImage,
                        VideoFile       = post.VideoFile,
                        Thumbnails      = GetPostedThumbnails(post.PostID),
                        PublicationDate = post.PublicationDate,
                        CreatedBy       = createdBy.PersonID,
                        NickName        = createdBy.NickName,
                        UserName        = createdBy.UserName,
                        ProfileAvatar   = (createdBy.ProfileAvatar != null) ? ByteArrayToBase64(createdBy.ProfileAvatar, createdBy.ProfileAvatar_MimeType) : defaultAvatar,
                        InteractButtons = GetInteractsCountDL(post.PostID, currentPersonID)
                    });
                }

                foreach (var repost in reposts)
                {
                    var post      = context.Post.Find(repost.ID_Post);
                    var createdBy = context.Person.Find(post.ID_Person);

                    postSection.Add(new PostSectionDTO()
                    {
                        PostID          = post.PostID,
                        Comment         = post.Comment,
                        GIFImage        = post.GIFImage,
                        VideoFile       = post.VideoFile,
                        Thumbnails      = GetPostedThumbnails(post.PostID),
                        PublicationDate = repost.PublicationDate,
                        CreatedBy       = createdBy.PersonID,
                        NickName        = createdBy.NickName,
                        UserName        = createdBy.UserName,
                        ProfileAvatar   = (createdBy.ProfileAvatar != null) ? ByteArrayToBase64(createdBy.ProfileAvatar, createdBy.ProfileAvatar_MimeType) : defaultAvatar,
                        InteractButtons = GetInteractsCountDL(post.PostID, currentPersonID),
                        RepostedBy      = (repost.ID_PersonThatRePost != currentPersonID) ? context.Person.Find(repost.ID_PersonThatRePost).NickName : "ti"
                    });
                }

                return(postSection);
            }
        }
예제 #13
0
        public bool LoginDL(string emailOrUsername, string password)
        {
            using (var context = new MiniBirdEntities())
            {
                var person = context.Person.Where(p => (p.UserName == "@" + emailOrUsername || p.Email == emailOrUsername) && p.Password == password).FirstOrDefault();

                if (person != null)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
 public string EncryptCookieValueDL(string emailOrUsername)
 {
     try
     {
         using (var context = new MiniBirdEntities())
         {
             return(EncryptToSHA256(context.Person.Where(p => p.UserName == "@" + emailOrUsername || p.Email == emailOrUsername).First().PersonID));
         }
     }
     catch
     {
         throw;
     }
 }
예제 #15
0
        public List <string> GetPostedThumbnails(int postID)
        {
            using (var context = new MiniBirdEntities())
            {
                List <string> postedThumbnails = new List <string>();
                var           thumbnails       = context.Thumbnail.Where(t => t.ID_Post == postID);

                foreach (var thumbnail in thumbnails)
                {
                    postedThumbnails.Add(thumbnail.FilePath);
                }

                return(postedThumbnails);
            }
        }
예제 #16
0
        public ListScreenDTO ListScreenCollectionDataDL(int listID, int personID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var currentList = context.List.Find(listID);

                    var listScreenDTO = new ListScreenDTO();
                    listScreenDTO.CurrentListSection.MyListID     = currentList.ListID;
                    listScreenDTO.CurrentListSection.Name         = currentList.Name;
                    listScreenDTO.CurrentListSection.Description  = currentList.Description;
                    listScreenDTO.CurrentListSection.MembersCount = context.UserToList.Where(ul => ul.ID_List == currentList.ListID).Count();
                    listScreenDTO.CanEdit = (personID == currentList.ID_Person) ? true : false;

                    var myLists = context.List.Where(ml => ml.ID_Person == personID);

                    foreach (var list in myLists)
                    {
                        listScreenDTO.MyListsSection.Add(new ListDTO()
                        {
                            MyListID    = list.ListID,
                            Name        = list.Name,
                            Description = list.Description,
                            Privacy     = (list.IsPrivate != true) ? Privacy.Public : Privacy.Private
                        });
                    }

                    IQueryable <UserToList> personsInThisList = context.UserToList.Where(ul => ul.ID_List == currentList.ListID);

                    foreach (var personITL in personsInThisList)
                    {
                        var posts   = context.Post.Where(p => p.ID_Person == personITL.ID_Person).ToList();
                        var reposts = context.RePost.Where(rp => rp.ID_PersonThatRePost == personITL.ID_Person).ToList();

                        listScreenDTO.PostSection.AddRange(FillPostSection(posts, personID, reposts));
                    }

                    listScreenDTO.PostSection = listScreenDTO.PostSection.OrderByDescending(ps => ps.PublicationDate).ToList();

                    return(listScreenDTO);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #17
0
        public void NewListDL(ListDTO data, int personID)
        {
            using (var context = new MiniBirdEntities())
            {
                context.List.Add(new List()
                {
                    Name         = data.Name,
                    Description  = data.Description,
                    IsPrivate    = (data.Privacy != Privacy.Public) ? true : false,
                    CreationDate = DateTime.Now,
                    ID_Person    = personID
                });

                context.SaveChanges();
            }
        }
예제 #18
0
        public MatchesFoundDTO FindMatchesDL(string queryString, int personID)
        {
            try
            {
                MatchesFoundDTO matchesFound = new MatchesFoundDTO();

                if (!string.IsNullOrWhiteSpace(queryString))
                {
                    using (var context = new MiniBirdEntities())
                    {
                        IQueryable <Hashtag> hashtagMatches = context.Hashtag.Where(h => h.Name.Contains(queryString)).Take(4);
                        IQueryable <Person>  profileMatches = context.Person.Where(p => p.NickName.Contains(queryString) || p.UserName.Contains(queryString)).Take(4);

                        if (hashtagMatches.Count() > 0 || profileMatches.Count() > 0)
                        {
                            foreach (var hashtag in hashtagMatches)
                            {
                                matchesFound.hashtagMatches.Add(new MatchesFoundDTO.HashtagMatchesDTO()
                                {
                                    HashtagID   = hashtag.HashtagID,
                                    HashtagName = hashtag.Name
                                });
                            }

                            foreach (var profile in profileMatches)
                            {
                                matchesFound.profileMatches.Add(new MatchesFoundDTO.ProfileMatchesDTO()
                                {
                                    PersonID      = profile.PersonID,
                                    NickName      = profile.NickName,
                                    UserName      = profile.UserName,
                                    ProfileAvatar = (profile.ProfileAvatar != null) ? ByteArrayToBase64(profile.ProfileAvatar, profile.ProfileAvatar_MimeType) : "/Content/images/defaultAvatar.png",
                                    Following     = context.Follow.Any(f => f.ID_Person == personID && f.ID_PersonFollowed == profile.PersonID)
                                });
                            }
                        }
                    }
                }

                return(matchesFound);
            }
            catch
            {
                throw;
            }
        }
예제 #19
0
        private string SaveGifOnServer(int postID, HttpPostedFileBase gifImage, HttpServerUtilityBase localServer)
        {
            try
            {
                if (gifImage == null && gifImage.ContentLength <= 0)
                {
                    throw new ArgumentException("Ninguna imágen seleccionada");
                }

                string thumbnailsPath = "/Content/thumbnails/" + postID;

                if (!Directory.Exists(thumbnailsPath))
                {
                    Directory.CreateDirectory(localServer.MapPath(thumbnailsPath));
                }

                // Obtiene datos del archivo
                byte[] data = new byte[] { };
                using (var binaryReader = new BinaryReader(gifImage.InputStream))
                {
                    data = binaryReader.ReadBytes(gifImage.ContentLength);
                }

                // Guarda imagen en el servidor
                string pathToNewFile = thumbnailsPath + "/" + gifImage.FileName;
                using (FileStream image = System.IO.File.Create(localServer.MapPath(pathToNewFile), data.Length))
                {
                    image.Write(data, 0, data.Length);
                    image.Flush();
                }

                return(pathToNewFile);
            }
            catch
            {
                using (var context = new MiniBirdEntities())
                {
                    Post post = context.Post.Find(postID);
                    context.Post.Remove(post);
                    context.SaveChanges();
                }

                throw;
            }
        }
예제 #20
0
        public InteractButtonsDTO GetInteractsCountDL(int postID, int personID)
        {
            using (var context = new MiniBirdEntities())
            {
                var replys  = context.Post.Where(ps => ps.InReplyTo == postID).Count();
                var reposts = context.RePost.Where(rp => rp.ID_Post == postID).Count();
                var likes   = context.LikePost.Where(lp => lp.ID_Post == postID).Count();

                return(new InteractButtonsDTO()
                {
                    ReplysCount = replys,
                    RepostsCount = reposts,
                    LikesCount = likes,
                    IReposted = context.RePost.Any(r => r.ID_PersonThatRePost == personID && r.ID_Post == postID),
                    ILiked = context.LikePost.Any(l => l.ID_PersonThatLikesPost == personID && l.ID_Post == postID)
                });
            }
        }
예제 #21
0
 public void EditListDL(ListDTO data)
 {
     try
     {
         using (var context = new MiniBirdEntities())
         {
             var list = context.List.Find(data.MyListID);
             list.Name        = data.Name;
             list.Description = data.Description;
             list.IsPrivate   = (data.Privacy != Privacy.Public) ? true : false;
             context.SaveChanges();
         }
     }
     catch
     {
         throw;
     }
 }
예제 #22
0
        public TimelineDTO TimelineCollectionDataDL(int personID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var person  = context.Person.Find(personID);
                    var posts   = context.Post.Where(ps => ps.ID_Person == personID && ps.InReplyTo == null).ToList();
                    var reposts = context.RePost.Where(rp => rp.ID_PersonThatRePost == person.PersonID).ToList();

                    var timelineDTO = new TimelineDTO();
                    timelineDTO.ProfileSection.PersonID       = person.PersonID;
                    timelineDTO.ProfileSection.UserName       = person.UserName;
                    timelineDTO.ProfileSection.NickName       = person.NickName;
                    timelineDTO.ProfileSection.ProfileHeader  = (person.ProfileHeader != null) ? ByteArrayToBase64(person.ProfileHeader, person.ProfileHeader_MimeType) : defaultHeader;
                    timelineDTO.ProfileSection.ProfileAvatar  = (person.ProfileAvatar != null) ? ByteArrayToBase64(person.ProfileAvatar, person.ProfileAvatar_MimeType) : defaultAvatar;
                    timelineDTO.ProfileSection.PostCount      = posts.Count();
                    timelineDTO.ProfileSection.FollowingCount = GetFollowingCount(context.Follow, person.PersonID);
                    timelineDTO.ProfileSection.FollowerCount  = GetFollowersCount(context.Follow, person.PersonID);
                    timelineDTO.TopTrendingsSection           = TopTrendings();

                    timelineDTO.PostSection.AddRange(FillPostSection(posts, person.PersonID, reposts));

                    var myFollowings = context.Follow.Where(f => f.ID_Person == personID);

                    foreach (var follow in myFollowings)
                    {
                        var personFollowedID   = context.Person.Find(follow.ID_PersonFollowed).PersonID;
                        var postsOfFollowing   = context.Post.Where(ps => ps.ID_Person == personFollowedID && ps.InReplyTo == null).ToList();
                        var repostsOfFollowing = context.RePost.Where(rp => rp.ID_PersonThatRePost == personFollowedID).ToList();

                        timelineDTO.PostSection.AddRange(FillPostSection(postsOfFollowing, person.PersonID, repostsOfFollowing));
                    }

                    timelineDTO.PostSection = timelineDTO.PostSection.OrderByDescending(ps => ps.PublicationDate).ToList();
                    return(timelineDTO);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #23
0
        public string SaveThumbnailOnServer(string imgBase64, int postID, HttpServerUtilityBase localServer, int iteration)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(imgBase64))
                {
                    throw new ArgumentNullException("Debe elegir una imágen.");
                }

                string thumbnailsPath = "/Content/thumbnails/" + postID;

                if (!Directory.Exists(thumbnailsPath))
                {
                    Directory.CreateDirectory(localServer.MapPath(thumbnailsPath));
                }

                // Get file data
                byte[] bytes         = imgBase64ToByteArray(imgBase64);
                string ext           = GetExtensionFromImgBase64(imgBase64);
                string pathToNewFile = thumbnailsPath + "/posted_thumbnail_" + iteration + '.' + ext;

                // Guardar imagen en el servidor
                using (FileStream image = File.Create(localServer.MapPath(pathToNewFile), bytes.Length))
                {
                    image.Write(bytes, 0, bytes.Length);
                    image.Flush();
                }

                return(pathToNewFile);
            }
            catch
            {
                using (var context = new MiniBirdEntities())
                {
                    Post post = context.Post.Find(postID);
                    context.Post.Remove(post);
                    context.SaveChanges();
                }

                throw;
            }
        }
예제 #24
0
        public void SendRepostDL(int postID, int personID)
        {
            using (var context = new MiniBirdEntities())
            {
                var repost = context.RePost.Any(lp => lp.ID_Post == postID && lp.ID_PersonThatRePost == personID);

                if (repost)
                {
                    context.RePost.Remove(context.RePost.Where(rp => rp.ID_Post == postID && rp.ID_PersonThatRePost == personID).FirstOrDefault());
                }
                else
                {
                    context.RePost.Add(new RePost()
                    {
                        ID_Post = postID, ID_PersonThatRePost = personID, PublicationDate = DateTime.Now
                    });
                }

                context.SaveChanges();
            }
        }
예제 #25
0
        public bool ToggleThemeDL(int userID)
        {
            using (var context = new MiniBirdEntities())
            {
                Person person = context.Person.Find(userID);

                if (person.DarkMode == true)
                {
                    person.DarkMode     = false;
                    ActiveSession.Theme = Theme.Light;
                }
                else
                {
                    person.DarkMode     = true;
                    ActiveSession.Theme = Theme.Dark;
                }

                context.SaveChanges();
                return(Convert.ToBoolean(person.DarkMode));
            }
        }
예제 #26
0
        public List <CheckboxListsDTO> CheckboxListsDL(int currentProfileID, int activeUser)
        {
            using (var context = new MiniBirdEntities())
            {
                var myLists = context.List.Where(ml => ml.ID_Person == activeUser);
                List <CheckboxListsDTO> checkboxListsDTO = new List <CheckboxListsDTO>();

                foreach (var list in myLists)
                {
                    checkboxListsDTO.Add(new CheckboxListsDTO()
                    {
                        MyListID     = list.ListID,
                        Name         = list.Name,
                        Description  = list.Description,
                        PersonalList = (context.UserToList.Any(ul => ul.ID_Person == currentProfileID && ul.ID_List == list.ListID)) ? true : false
                    });
                }

                return(checkboxListsDTO);
            }
        }
예제 #27
0
        public void GiveALikeDL(int postID, int personID)
        {
            using (var context = new MiniBirdEntities())
            {
                var like = context.LikePost.Where(lp => lp.ID_Post == postID && lp.ID_PersonThatLikesPost == personID).FirstOrDefault();

                if (like != null)
                {
                    context.LikePost.Remove(like);
                }
                else
                {
                    context.LikePost.Add(new LikePost()
                    {
                        ID_Post = postID, ID_PersonThatLikesPost = personID, DateOfAction = DateTime.Now
                    });
                }

                context.SaveChanges();
            }
        }
예제 #28
0
        private List <TopTrendingsDTO> TopTrendings()
        {
            using (var context = new MiniBirdEntities())
            {
                IQueryable <Hashtag>   topTrendings    = context.Hashtag.OrderByDescending(h => h.UseCount).Take(10);
                List <TopTrendingsDTO> topTrendingsDTO = new List <TopTrendingsDTO>();

                if (topTrendings.Count() > 0)
                {
                    foreach (var trending in topTrendings)
                    {
                        topTrendingsDTO.Add(new TopTrendingsDTO()
                        {
                            Name     = trending.Name,
                            UseCount = trending.UseCount
                        });
                    }
                }

                return(topTrendingsDTO);
            }
        }
예제 #29
0
        public void RemoveListDL(int listID, int personID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    List listToRemove = context.List.Find(listID);

                    foreach (var row in context.UserToList.Where(ul => ul.ID_List == listID))
                    {
                        context.UserToList.Remove(row);
                    }

                    context.List.Remove(listToRemove);
                    context.SaveChanges();
                }
            }
            catch
            {
                throw;
            }
        }
예제 #30
0
        public HashtagDTO GetPostsUsingHashtagDL(string name)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    IQueryable <Post> posts      = context.Post.Where(p => p.Hashtag.Any(h => h.Name == name));
                    HashtagDTO        hashtagDTO = new HashtagDTO();
                    hashtagDTO.Name = name;

                    foreach (var post in posts)
                    {
                        var createdBy = context.Person.Find(post.ID_Person);

                        hashtagDTO.PostSection.Add(new PostSectionDTO()
                        {
                            PostID          = post.PostID,
                            Comment         = post.Comment,
                            GIFImage        = post.GIFImage,
                            VideoFile       = post.VideoFile,
                            Thumbnails      = new AccountDL().GetPostedThumbnails(post.PostID),
                            PublicationDate = post.PublicationDate,
                            CreatedBy       = createdBy.PersonID,
                            NickName        = createdBy.NickName,
                            UserName        = createdBy.UserName,
                            ProfileAvatar   = (createdBy.ProfileAvatar != null) ? ByteArrayToBase64(createdBy.ProfileAvatar, createdBy.ProfileAvatar_MimeType) : "/Content/images/defaultAvatar.png",
                            InteractButtons = new AccountDL().GetInteractsCountDL(post.PostID, ActiveSession.GetPersonID()),
                        });
                    }

                    return(hashtagDTO);
                }
            }
            catch
            {
                throw;
            }
        }