Exemplo n.º 1
0
        /// <summary>
        /// Get All Thread in Thread table
        /// </summary>
        /// <returns>list</returns>
        public List <ThreadBasicInfo> GetAllThread()
        {
            var listThread = new List <ThreadBasicInfo>();

            try
            {
                List <int> userIdThread;
                using (var db = new Ws_DataContext())
                {
                    userIdThread = db.Threads.OrderBy(x => x.ThreadId).Select(x => x.ThreadId).ToList();
                }

                using (var db = new ThreadDAL())
                {
                    foreach (int threadId in userIdThread)
                    {
                        ThreadBasicInfo threadBasic = db.GetFullThreadBasicInformation(threadId);
                        listThread.Add(threadBasic);
                    }
                }
            }
            catch (Exception)
            {
                //throw;
            }

            return(listThread);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get list newest thread
        /// </summary>
        /// <returns></returns>
        public List <ThreadBasicInfo> GetNewestNumberThread(int top)
        {
            List <ThreadBasicInfo> topNewestThread = new List <ThreadBasicInfo>();

            try
            {
                var threadListBasic = new List <ThreadBasicInfo>();
                using (var db = new ThreadDAL())
                {
                    List <Thread> threadList = db.GetNewThread();
                    if (threadList != null)
                    {
                        foreach (Thread thread in threadList)
                        {
                            //Get Creator of Thread
                            Ws_User creatorThread;
                            using (var dbUser = new UserDAL())
                            {
                                creatorThread = dbUser.GetUserById(thread.UserId);
                            }
                            threadListBasic.Add(new ThreadBasicInfo
                            {
                                ThreadID    = thread.ThreadId,
                                ThreadName  = thread.Title,
                                Creator     = creatorThread.UserName,
                                CreatedDate = thread.CreatedDate.ToString("H:mm:ss dd/MM/yy"),
                                Status      = thread.Status,
                            });
                        }
                    }
                }

                // Get top newest Thread
                topNewestThread = threadListBasic.OrderByDescending(x => x.CreatedDate).Take(top).ToList();
            }
            catch (Exception)
            {
                //throw;
            }
            return(topNewestThread);
        }
Exemplo n.º 3
0
        public ReportBasicInfoDTO GetReportBasicInformation(int reportId)
        {
            try
            {
                var    reportBasic = new ReportBasicInfoDTO();
                Report report;
                string reportorName = "";
                using (var db = new Ws_DataContext())
                {
                    report = db.Reports.FirstOrDefault(x => x.ReportId == reportId);

                    if (report != null)
                    {
                        reportBasic.ReportId = report.ReportId;
                        reportBasic.UserId   = report.UserId;
                        var userMakeReport            = db.Ws_User.FirstOrDefault(x => x.UserID == reportBasic.UserId);
                        var userInformationMakeReport = db.User_Information.FirstOrDefault(x => x.UserID == reportBasic.UserId);
                        if (userMakeReport != null)
                        {
                            reportBasic.ReportorUserName = userMakeReport.UserName;
                        }

                        if (userInformationMakeReport != null)
                        {
                            reportBasic.ReportorImage = userInformationMakeReport.ProfileImage;
                        }
                        else
                        {
                            reportBasic.ReportorImage = "~/Content/Images/Slider/avatar_default.png";
                        }

                        reportBasic.Reason      = report.Reason;
                        reportBasic.ReportTime  = report.ReportTime.ToString("HH:mm:ss dd/MM/yyyy");
                        reportBasic.Type        = report.Type;
                        reportBasic.ReportTo    = report.ReportTo;
                        reportBasic.Status      = report.Status;
                        reportBasic.UpdatedTime = report.UpdatedTime.ToString("HH:mm:ss dd/MM/yyyy");

                        if (reportBasic.Type.Equals(WsConstant.ReportType.REPORT_USER))
                        {
                            var userIsReported = db.Ws_User.FirstOrDefault(x => x.UserID == reportBasic.ReportTo);
                            if (userIsReported != null)
                            {
                                reportBasic.ReportToName = userIsReported.UserName;
                            }

                            var userIsReportedInformation = db.User_Information.FirstOrDefault(x => x.UserID == reportBasic.ReportTo);
                            if (userIsReportedInformation != null)
                            {
                                reportBasic.ReportToImage = userIsReportedInformation.ProfileImage;
                            }
                        }
                        else if (reportBasic.Type.Equals(WsConstant.ReportType.REPORT_EVENT))
                        {
                            var eventIsReported = db.Events.FirstOrDefault(x => x.EventID == reportBasic.ReportTo);
                            if (eventIsReported != null)
                            {
                                reportBasic.ReportToName = eventIsReported.EventName;
                            }

                            using (var eventDal = new EventDAL())
                            {
                                reportBasic.ReportToImage = eventDal.GetMainImageEventById(reportBasic.ReportTo).ImageUrl;
                            }
                        }
                        else if (reportBasic.Type.Equals(WsConstant.ReportType.REPORT_THREAD))
                        {
                            var threadIsReported = db.Threads.FirstOrDefault(x => x.ThreadId == reportBasic.ReportTo);
                            if (threadIsReported != null)
                            {
                                reportBasic.ReportToName = threadIsReported.Title;
                            }

                            using (var threadDal = new ThreadDAL())
                            {
                                reportBasic.ReportToImage = threadDal.GetAllImageThreadById(reportBasic.ReportTo).First();
                            }
                        }
                        else if (reportBasic.Type.Equals(WsConstant.ReportType.REPORT_ORGANAZATION))
                        {
                            var orgIsReported = db.Organizations.FirstOrDefault(x => x.OrganizationId == reportBasic.ReportTo);
                            if (orgIsReported != null)
                            {
                                reportBasic.ReportToName  = orgIsReported.OrganizationName;
                                reportBasic.ReportToImage = orgIsReported.LogoUrl;
                            }
                        }
                    }
                }

                return(reportBasic);
            }
            catch (Exception)
            {
                return(null);
                //throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// get report statistic data
        /// </summary>
        /// <param name="typeReport"></param>
        /// <returns></returns>
        public List <ReportStatisticDTO> GetListReportByType(string typeReport)
        {
            List <ReportStatisticDTO> listReport = new List <ReportStatisticDTO>();
            List <int> isReportedIdList;

            try
            {
                var db        = new Ws_DataContext();
                var eventDal  = new EventDAL();
                var threadDal = new ThreadDAL();

                // lấy ra danh sách id bị report theo type
                isReportedIdList =
                    db.Reports.Where(x => x.Type.Equals(typeReport)).Select(x => x.ReportTo).Distinct().ToList();

                foreach (var id in isReportedIdList)
                {
                    var reportStatistic = new ReportStatisticDTO();
                    reportStatistic.IsReportedId = id;

                    if (typeReport.Equals(WsConstant.ReportType.REPORT_USER))
                    {
                        var userIsReported = db.Ws_User.FirstOrDefault(x => x.UserID == id);
                        if (userIsReported != null)
                        {
                            reportStatistic.IsreportedUserName   = userIsReported.UserName;
                            reportStatistic.IsreportedUserStatus = userIsReported.IsActive;
                        }

                        var userIsReportedInformation = db.User_Information.FirstOrDefault(x => x.UserID == id);
                        if (userIsReportedInformation != null)
                        {
                            reportStatistic.IsreportedImage = userIsReportedInformation.ProfileImage;
                        }
                    }
                    else if (typeReport.Equals(WsConstant.ReportType.REPORT_EVENT))
                    {
                        var eventIsReported = db.Events.FirstOrDefault(x => x.EventID == id);
                        if (eventIsReported != null)
                        {
                            reportStatistic.IsreportedUserName   = eventIsReported.EventName;
                            reportStatistic.IsreportedUserStatus = eventIsReported.Status;
                        }

                        reportStatistic.IsreportedImage = eventDal.GetMainImageEventById(id).ImageUrl;
                    }
                    else if (typeReport.Equals(WsConstant.ReportType.REPORT_THREAD))
                    {
                        var threadIsReported = db.Threads.FirstOrDefault(x => x.ThreadId == id);
                        if (threadIsReported != null)
                        {
                            reportStatistic.IsreportedUserName   = threadIsReported.Title;
                            reportStatistic.IsreportedUserStatus = threadIsReported.Status;
                        }

                        reportStatistic.IsreportedImage = threadDal.GetAllImageThreadById(id).First();
                    }
                    else if (typeReport.Equals(WsConstant.ReportType.REPORT_ORGANAZATION))
                    {
                        var orgIsReported = db.Organizations.FirstOrDefault(x => x.OrganizationId == id);
                        if (orgIsReported != null)
                        {
                            reportStatistic.IsreportedUserName   = orgIsReported.OrganizationName;
                            reportStatistic.IsreportedImage      = orgIsReported.LogoUrl;
                            reportStatistic.IsreportedUserStatus = orgIsReported.IsActive;
                        }
                    }


                    reportStatistic.TotalReportedTimes = CountIsReportedTime(id, typeReport);
                    reportStatistic.NewReportedTimes   = CountNewReportedTime(id, typeReport);

                    listReport.Add(reportStatistic);
                }
            }
            catch (Exception)
            {
                //throw;
            }

            return(listReport);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get full information of User
        /// #Note: If you add new field to UserBasicInfoDTO model -
        ///        Please write code to set that information in this function
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>UserBasicInfoDTO</returns>
        public UserBasicInfoDTO GetFullInforOfUserAsBasicUser(int userId)
        {
            UserBasicInfoDTO currentUser = new UserBasicInfoDTO();

            int     numberEventDonatedIn = 0;
            decimal totalMoneyDonatedIn  = 0;
            decimal lastDonateMoney      = 0;
            string  lastDonateDate       = "";

            int numberOfPost = 0;

            try
            {
                Ws_User          wsUser          = GetUserById(userId);
                User_Information userInformation = GetUserInformation(userId);

                //Get infomation about donation of this user
                using (var db = new DonationDAL())
                {
                    numberEventDonatedIn = db.GetNumberEventDonatedInByUsingUserId(userId);
                    totalMoneyDonatedIn  = db.GetTotalMoneyDonatedInByUsingUserId(userId);

                    Donation lastDonation = db.GetLastDonateInformation(userId);

                    if (lastDonation != null)
                    {
                        lastDonateMoney = lastDonation.DonatedMoney;
                        lastDonateDate  = lastDonation.DonatedDate.ToString("H:mm:ss dd/MM/yy");
                    }
                }

                //Get number of post for current user
                using (var db = new ThreadDAL())
                {
                    numberOfPost = db.GetNumberOfPostPerUser(userId);
                }
                using (var db = new OrganizationDAL())
                {
                    Organization org = db.GetOrganizationById(userId);
                    if (org != null)
                    {
                        currentUser.OrganazationName = org.OrganizationName;
                    }

                    if (currentUser.OrganazationName == "")
                    {
                        currentUser.OrganazationName = "Chưa có";
                    }
                }
                using (var db = new Ws_DataContext())
                {
                    currentUser.JoinedDate = db.Ws_User.Where(x => x.UserID == userId).SingleOrDefault().CreatedDate.ToString("dd/mm/yyyy");
                }

                //get ranking information
                WsRanking  ranking = new WsRanking();
                RankingDTO rank    = new RankingDTO();


                //Set information for user which want to get
                currentUser.UserId      = userId;
                currentUser.UserName    = wsUser.UserName;
                currentUser.AccountType = wsUser.AccountType;
                currentUser.IsActive    = wsUser.IsActive;
                currentUser.IsVerify    = wsUser.IsVerify;

                currentUser.Email = wsUser.Email;
                if (userInformation != null)
                {
                    rank = ranking.RankingWithPoint(userInformation.Point);
                    currentUser.FacebookUri   = userInformation.FacebookUrl;
                    currentUser.FullName      = userInformation.FullName;
                    currentUser.ProfileImage  = userInformation.ProfileImage;
                    currentUser.Gender        = userInformation.Gender;
                    currentUser.Phone         = userInformation.Phone;
                    currentUser.Address       = userInformation.UserAddress;
                    currentUser.UserSignature = userInformation.UserSignature;

                    if (userInformation.DoB != null)
                    {
                        currentUser.DOB = userInformation.DoB.Value.ToString("dd/MM/yyyy");
                    }

                    currentUser.Country     = userInformation.Country;
                    currentUser.FacebookUri = userInformation.FacebookUrl;
                    currentUser.CreateDate  = wsUser.CreatedDate.ToString("dd/MM/yyyy");
                    currentUser.Point       = userInformation.Point;
                }

                currentUser.NumberOfPost = numberOfPost;

                if (rank.CurrentRank == 0)
                {
                    currentUser.CurrentRank = "Mới";
                }
                else if (rank.CurrentRank == 200)
                {
                    currentUser.CurrentRank = "Đồng";
                }
                else if (rank.CurrentRank == 500)
                {
                    currentUser.CurrentRank = "Bạc";
                }
                else if (rank.CurrentRank == 2000)
                {
                    currentUser.CurrentRank = "Vàng";
                }
                else if (rank.CurrentRank == 5000)
                {
                    currentUser.CurrentRank = "Bạch Kim";
                }
                else if (rank.CurrentRank == 10000)
                {
                    currentUser.CurrentRank = "Kim Cương";
                }

                currentUser.RankPercent          = rank.RankPercent;
                currentUser.NumberEventDonatedIn = numberEventDonatedIn;
                currentUser.TotalMoneyDonatedIn  = totalMoneyDonatedIn;
                currentUser.LastDonateMoney      = lastDonateMoney;
                currentUser.LastDonateDate       = lastDonateDate;
            }
            catch (Exception)
            {
                //throw;
            }

            return(currentUser);
        }