Пример #1
0
        public List <EventBasicInfo> GetAllEvents()
        {
            var listEvent = new List <EventBasicInfo>();

            try
            {
                List <int> IdList;
                using (var db = new Ws_DataContext())
                {
                    IdList = db.Events.Select(x => x.EventID).ToList();
                }

                using (var db = new EventDAL())
                {
                    foreach (int eventId in IdList)
                    {
                        EventBasicInfo eventBasic = db.GetFullEventBasicInformation(eventId);
                        listEvent.Add(eventBasic);
                    }
                }
            }
            catch (Exception)
            {
                //throw;
            }

            return(listEvent);
        }
Пример #2
0
        //public List<DonationDAL> GetDonationHistoryOfUser(int userId)
        //{

        //}

        public DonationDTO GetFullInformationOfDonation(int donationId)
        {
            DonationDTO currentDonation = new DonationDTO();

            try
            {
                Donation donation;
                string   userName     = "";
                string   userImageUrl = "";
                using (var db = new Ws_DataContext())
                {
                    donation = db.Donations.FirstOrDefault(x => x.DonationId == donationId);
                    var wsUser = db.Ws_User.FirstOrDefault(x => x.UserID == donation.UserId);
                    if (wsUser != null)
                    {
                        userName = wsUser.UserName;
                    }

                    var userInformation = db.User_Information.FirstOrDefault(x => x.UserID == donation.UserId);
                    if (userInformation != null)
                    {
                        userImageUrl = userInformation.ProfileImage;
                    }
                }

                using (var db = new EventDAL())
                {
                    currentDonation.EventBasicInformation = db.GetFullEventBasicInformation(donation.EventId);
                }

                currentDonation.DonationId   = donation.DonationId;
                currentDonation.UserId       = donation.UserId;
                currentDonation.UserName     = userName;
                currentDonation.UserImageUrl = userImageUrl;
                currentDonation.EventId      = donation.EventId;
                currentDonation.TradeCode    = donation.TradeCode;
                currentDonation.DonatedMoney = donation.DonatedMoney;
                currentDonation.Content      = donation.Content;
                currentDonation.DonatedDate  = donation.DonatedDate.ToString("hh:mm:ss dd/MM/yy");
                currentDonation.IsPublic     = donation.IsPublic;
            }
            catch (Exception)
            {
                //throw;
            }
            return(currentDonation);
        }
Пример #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;
            }
        }
Пример #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);
        }