Beispiel #1
0
        private List <DashboardSaleBoxToken> getDashboardSaleStats(DateRangeToken dates, int userId, short currencyId, int?storeId)
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var stats = context.tvf_DB_GetAuthorSalesStats(dates.from, dates.to, userId, currencyId, storeId).FirstOrDefault();

                    if (stats == null)
                    {
                        return(EmptySalesBoxesList);
                    }

                    var list = new List <DashboardSaleBoxToken>
                    {
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.ONE_TIME, stats.AuthorTotalOnetimeSales, stats.AuthorTotalOnetimeQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.SUBSCRIPTION, stats.AuthorTotalSubscriptionSales, stats.AuthorTotalSubscriptionQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.RENTAL, stats.AuthorTotalRentalSales, stats.AuthorTotalRentalQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.SALES_BY_AFFILIATES, stats.ByAffiliateTotalSales, stats.ByAffiliateTotalQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.AFFILIATE_SALES, stats.AffiliateTotalSales, stats.AffiliateTotalQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.SUBSCRIPTION_CANCELLATION, stats.TotalCancelled, stats.TotalCancelledQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.REFUNDS, stats.TotalRefund, stats.TotalRefundQty),
                        new DashboardSaleBoxToken(DashboardEnums.eSaleBoxType.COUPONS_USED, stats.TotalCouponValue, stats.TotalCouponQty)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("getDashboardSaleStats", ex, CommonEnums.LoggerObjectTypes.Dashboard);
                return(EmptySalesBoxesList);
            }
        }
Beispiel #2
0
 private void ValidateDataContext()
 {
     if (_dataContext == null)
     {
         _dataContext = new lfeAuthorEntities();
     }
 }
Beispiel #3
0
        public List <StateDTO> States()
        {
            if (_states.Any())
            {
                return(_states);
            }

            try
            {
                _states = GeoStatesRepository.GetAll().Select(x => x.Entity2StateDto()).ToList();

                return(_states);
            }
            catch (Exception ex)
            {
                Logger.Error("get states", ex, CommonEnums.LoggerObjectTypes.Geo);

                using (var context = new lfeAuthorEntities())
                {
                    _states = context.GEO_States.Select(x => x.Entity2StateDto()).ToList();

                    return(_states);
                }
            }
        }
        public AdminVideoStatsToken GetVideoStats()
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetTotals().FirstOrDefault();

                    if (totals == null)
                    {
                        return(new AdminVideoStatsToken());
                    }

                    return(new AdminVideoStatsToken
                    {
                        TotalUploaded = totals.TotalVideos ?? 0
                        , CourseAttached = totals.TotalAttached2ActiveCourses ?? 0
                        , NotAttached = totals.UnattachedVideos ?? 0
                        , TotalPreviews = totals.VideoPreviews ?? 0
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard video stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new AdminVideoStatsToken());
            }
        }
Beispiel #5
0
        public long GetTotalVideosDuration()
        {
            long totalSeconds = 0;

            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var videos = context.USER_Videos.ToList();

                    foreach (var video in videos)
                    {
                        var duration = video.Duration;

                        totalSeconds += duration.Duration2Seconds();
                    }

                    return(totalSeconds);
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }
        public AuthorTotalStatsToken GetAuthorTotalStats()
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetAuthorTotalStats().FirstOrDefault();

                    if (totals == null)
                    {
                        return(new AuthorTotalStatsToken());
                    }

                    return(new AuthorTotalStatsToken
                    {
                        AverageCourseChapters = totals.AverageCourseChapters.FormatDecimal(2)
                        , AverageCoursesPerAuthor = totals.AverageCoursesPerAuthor.FormatDecimal(2)
                        , AverageBundlesPerAuthor = totals.AverageBundlesPerAuthor.FormatDecimal(2)
                        , AverageFreeCoursesPerAuthor = totals.AverageFreeCoursesPerAuthor.FormatDecimal(2)
                        , TotalFreeCourses = totals.TotalFreeCourses
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard author total stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new AuthorTotalStatsToken());
            }
        }
        public List <AuthorPeriodStatsBoxToken> GetAuthorPeriodStats(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod   = PeriodSelection2DateRange(period);
                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals         = context.tvf_FACT_DASH_GetAuthorPeriodStats(reportPeriod.from, reportPeriod.to).FirstOrDefault();
                    var previousTotals = context.tvf_FACT_DASH_GetAuthorPeriodStats(previousPeriod.from, previousPeriod.to).FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <AuthorPeriodStatsBoxToken>());
                    }

                    var list = new List <AuthorPeriodStatsBoxToken>
                    {
                        ReportEnums.eStatsTypes.ActiveAuthors.Type2AuthorPeriodStatsBoxToken(1, totals.ActiveAuthors, previousTotals != null ? previousTotals.ActiveAuthors : 0),
                        ReportEnums.eStatsTypes.AvgAuthorLogins.Type2AuthorPeriodStatsBoxToken(2, totals.AvgAuthorLogins.FormatDecimal(2), previousTotals != null ? previousTotals.AvgAuthorLogins.FormatDecimal(2) : 0),
                        ReportEnums.eStatsTypes.DashboardViews.Type2AuthorPeriodStatsBoxToken(3, totals.DashboardViews, previousTotals != null ? previousTotals.DashboardViews : 0),
                        ReportEnums.eStatsTypes.CouponsCreated.Type2AuthorPeriodStatsBoxToken(4, totals.TotalCouponsCreated, previousTotals != null ? previousTotals.TotalCouponsCreated : 0)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard author period stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <AuthorPeriodStatsBoxToken>());
            }
        }
        public LearnerPeriodStatsBoxToken GetLearnerPeriodCouponStats(AdminDashboardFiltersToken filter)
        {
            try
            {
                var reportPeriod   = PeriodSelection2DateRange(filter.period);
                var previousPeriod = Period2Previous(filter.period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals   = context.tvf_FACT_DASH_GetLearnerPeriodCouponStats(filter.currencyId, reportPeriod.from, reportPeriod.to).FirstOrDefault();
                    var currency = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == filter.currencyId);

                    if (totals == null || currency == null)
                    {
                        return(new LearnerPeriodStatsBoxToken());
                    }

                    var previousTotals = context.tvf_FACT_DASH_GetLearnerPeriodCouponStats(filter.currencyId, previousPeriod.from, previousPeriod.to).FirstOrDefault();

                    var couponValue = ReportEnums.eStatsTypes.LearnerCouponsClaimedValue.Type2LearnerPeriodStatsBoxToken(1, totals.TotalDiscount.FormatDecimal(2), previousTotals != null ? previousTotals.TotalDiscount.FormatDecimal(2) : 0);

                    couponValue.DisplayedValue = String.Format("{0}{1}", currency.Symbol, totals.TotalDiscount.FormatDecimal(2));

                    var box = ReportEnums.eStatsTypes.LearnerCouponsClaimed.Type2LearnerPeriodStatsBoxToken(1, totals.TotalCouponsClaimed, previousTotals != null ? previousTotals.TotalCouponsClaimed : 0, couponValue);

                    return(box);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard learner period coupon stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new LearnerPeriodStatsBoxToken());
            }
        }
Beispiel #9
0
        public List <CountryDTO> ActiveCountries()
        {
            if (_activeCountries.Any())
            {
                return(_activeCountries);
            }

            try
            {
                //_activeCountries = GeoCountriesRepository.GetMany(x => x.IsActive).Select(x => x.Entity2CountryDto()).ToList();

                //return _activeCountries;

                using (var context = new lfeAuthorEntities())
                {
                    _activeCountries = context.GEO_CountriesLib.Where(x => x.IsActive).ToList().Select(x => x.Entity2CountryDto()).ToList();

                    return(_activeCountries);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("get countries", ex, CommonEnums.LoggerObjectTypes.Geo);

                //using (var context = new lfeAuthorEntities())
                //{
                //    _activeCountries = context.GEO_CountriesLib.Where(x => x.IsActive).ToList().Select(x => x.Entity2CountryDto()).ToList();

                //    return _activeCountries;
                //}

                return(new List <CountryDTO>());
            }
        }
Beispiel #10
0
 public void Dispose()
 {
     _unitOfWork?.Dispose();
     if (_dataContext != null)
     {
         _dataContext.Dispose();
         _dataContext = null;
     }
     // GC.SuppressFinalize(this);
 }
Beispiel #11
0
        public void UpdateWebStoreLog(int storeId, out string error)
        {
            error = string.Empty;
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var entity = context.WebStoresChangeLog.SingleOrDefault(x => x.StoreId == storeId);

                    if (entity == null)
                    {
                        context.WebStoresChangeLog.Add(new WebStoresChangeLog
                        {
                            StoreId        = storeId
                            , LastUpdateOn = DateTime.Now
                        });
                    }
                    else
                    {
                        entity.LastUpdateOn = DateTime.Now;
                    }

                    context.SaveChanges();
                }


                //var entity = WebStoresChangeLogRepository.Get(x => x.StoreId == storeId);

                //if (entity == null)
                //{
                //    WebStoresChangeLogRepository.Add(new WebStoresChangeLog
                //    {
                //        StoreId       = storeId
                //        ,LastUpdateOn = DateTime.Now
                //    });
                //}
                //else
                //{
                //    entity.LastUpdateOn = DateTime.Now;

                //    WebStoresChangeLogRepository.Update(entity);
                //}

                //WebStoresChangeLogRepository.UnitOfWork.CommitAndRefreshChanges();
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("Update WebStore log", ex, CommonEnums.LoggerObjectTypes.WebStore);
            }
        }
Beispiel #12
0
        public Repository(IUnitOfWork unitOfWork)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException(nameof(unitOfWork));
            }

            _unitOfWork = unitOfWork;

            _dataContext = new lfeAuthorEntities();
            _dataContext.Configuration.LazyLoadingEnabled = false;

            Dbset = _dataContext.Set <TEntity>();
        }
Beispiel #13
0
        private static void initTemplates()
        {
            _templates = new List <CertificateTemplateDTO>();

            using (var context = new lfeAuthorEntities())
            {
                var templates = context.CERT_TemplatesLOV.Where(x => x.IsActive).ToList();

                foreach (var entity in templates)
                {
                    _templates.Add(entity.Entity2TemplateDto());
                }
            }
        }
Beispiel #14
0
        public List <BaseOrderLineDTO> GetSalesRows(int userId, DashboardEnums.eSaleBoxType type, FiltersToken filter)
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    string paymentSource = null;
                    byte?  lineTypeId    = null;


                    switch (type)
                    {
                    case DashboardEnums.eSaleBoxType.ONE_TIME:
                        paymentSource = DashboardEnums.eSaleSources.AS.ToString();
                        lineTypeId    = (byte)BillingEnums.eOrderLineTypes.SALE;
                        break;

                    case DashboardEnums.eSaleBoxType.SUBSCRIPTION:
                        paymentSource = DashboardEnums.eSaleSources.AS.ToString();
                        lineTypeId    = (byte)BillingEnums.eOrderLineTypes.SUBSCRIPTION;
                        break;

                    case DashboardEnums.eSaleBoxType.RENTAL:
                        paymentSource = DashboardEnums.eSaleSources.AS.ToString();
                        lineTypeId    = (byte)BillingEnums.eOrderLineTypes.RENTAL;
                        break;

                    case DashboardEnums.eSaleBoxType.SALES_BY_AFFILIATES:
                        paymentSource = DashboardEnums.eSaleSources.BAFS.ToString();
                        break;

                    case DashboardEnums.eSaleBoxType.AFFILIATE_SALES:
                        paymentSource = DashboardEnums.eSaleSources.AFS.ToString();
                        break;
                    }

                    var result = context.tvf_DB_GetUserSalesDetails(filter.DateRange.from, filter.DateRange.to, userId, filter.CurrencyId, filter.StoreId, paymentSource, lineTypeId).ToList();
                    var lines  = result.Select(x => x.DbSaleEntity2BaseOrderLineDto()).OrderByDescending(x => x.OrderNumber).ToList();

                    return(lines);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetSalesRows", ex, CommonEnums.LoggerObjectTypes.Dashboard);

                return(new List <BaseOrderLineDTO>());
            }
        }
Beispiel #15
0
        public List <DashboardPayoutToken> GetNextPayout(int userId)
        {
            try
            {
                var now      = DateTime.Now;
                var previous = now.AddMonths(-1);

                using (var context = new lfeAuthorEntities())
                {
                    var currentPayout = context.sp_PO_GetMonthlyPayoutReport(now.Year, now.Month, LFE_COMMISSION_PERCENT, userId, null).Select(x => x.Entity2DashboardPayoutToken()).ToList();

                    if (currentPayout.Count.Equals(0))
                    {
                        return new List <DashboardPayoutToken>
                               {
                                   new DashboardPayoutToken
                                   {
                                       Sales  = 0
                                       , Fees = 0
                                       , Mbg  = 0
                                                // ,TotalPayout = 0
                                       , Currency = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == DEFAULT_CURRENCY_ID)
                                   }
                               }
                    }
                    ;

                    var previousPayout = context.sp_PO_GetMonthlyPayoutReport(previous.Year, previous.Month, LFE_COMMISSION_PERCENT, userId, null).Select(x => x.Entity2DashboardPayoutToken()).ToList();

                    foreach (var token in currentPayout)
                    {
                        var t = token;

                        var previousToken = previousPayout.FirstOrDefault(x => x.Currency.CurrencyId == t.Currency.CurrencyId);

                        token.IsUp = previousToken == null || previousToken.TotalPayout <= t.TotalPayout;
                    }


                    return(currentPayout);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetNextPayout", ex, CommonEnums.LoggerObjectTypes.Dashboard);

                return(new List <DashboardPayoutToken>());
            }
        }
Beispiel #16
0
        public DateTime?GetCourseLastUpdate(Guid uid, out string error)
        {
            error = string.Empty;
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var entity = context.CRS_CourseChangeLog.SingleOrDefault(x => x.Uid == uid);

                    return(entity?.LastUpdateOn);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("API::Get Course LastUpdate", ex, CommonEnums.LoggerObjectTypes.Course);
                return(null);
            }
        }
Beispiel #17
0
        public List <BaseOrderLineDTO> GetCouponRows(int userId, FiltersToken filter)
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var result = context.tvf_DB_GetUserCouponUsageDetails(filter.DateRange.from, filter.DateRange.to, userId, filter.CurrencyId, filter.StoreId, null, null).Where(x => x.CouponInstanceId != null).ToList();
                    var lines  = result.Select(x => x.DbCouponEntity2BaseOrderLineDto()).OrderByDescending(x => x.OrderNumber).ToList();

                    return(lines);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetSalesRows", ex, CommonEnums.LoggerObjectTypes.Dashboard);

                return(new List <BaseOrderLineDTO>());
            }
        }
        public List <LearnerPeriodStatsBoxToken> GetLearnerPeriodStats(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod   = PeriodSelection2DateRange(period);
                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetLearnerPeriodStats(reportPeriod.from, reportPeriod.to).FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <LearnerPeriodStatsBoxToken>());
                    }

                    var previousTotals = context.tvf_FACT_DASH_GetLearnerPeriodStats(previousPeriod.from, previousPeriod.to).FirstOrDefault();

                    var avgLogin     = ReportEnums.eStatsTypes.AvgLearnerLogin.Type2LearnerPeriodStatsBoxToken(0, totals.AvgLearnerLogin.FormatDecimal(2), previousTotals != null ? previousTotals.AvgLearnerLogin.FormatDecimal(2) : 0);
                    var buyCompltete = ReportEnums.eStatsTypes.PurchaseComplete.Type2LearnerPeriodStatsBoxToken(2, totals.TotalPurchaseComplete, previousTotals != null ? previousTotals.TotalPurchaseComplete: 0);

                    decimal avgWatched     = totals.TotalCoursesWatched > 0 ? totals.TotalVideosWatched / totals.TotalCoursesWatched : 0;
                    decimal prevAvgWatched = previousTotals != null ? (previousTotals.TotalCoursesWatched > 0 ? previousTotals.TotalVideosWatched / previousTotals.TotalCoursesWatched : 0) : 0;

                    var list = new List <LearnerPeriodStatsBoxToken>
                    {
                        ReportEnums.eStatsTypes.ActiveLearners.Type2LearnerPeriodStatsBoxToken(1, totals.TotalActiveLearners, previousTotals != null ? previousTotals.TotalActiveLearners : 0, avgLogin),
                        ReportEnums.eStatsTypes.VideoPreviewWatched.Type2LearnerPeriodStatsBoxToken(2, totals.TotalVideoPreveiwWatched, previousTotals != null ? previousTotals.TotalVideoPreveiwWatched : 0),
                        ReportEnums.eStatsTypes.CoursePreviewEntered.Type2LearnerPeriodStatsBoxToken(3, totals.TotalCoursePreviewEntered, previousTotals != null ? previousTotals.TotalCoursePreviewEntered: 0),
                        ReportEnums.eStatsTypes.PurchasePageEntered.Type2LearnerPeriodStatsBoxToken(4, totals.TotalPurchasePageEntered, previousTotals != null ? previousTotals.TotalPurchasePageEntered: 0, buyCompltete),
                        ReportEnums.eStatsTypes.AvgVideosWatchedPerCourse.Type2LearnerPeriodStatsBoxToken(5, avgWatched.FormatDecimal(2), prevAvgWatched.FormatDecimal(2)),
                        ReportEnums.eStatsTypes.TotalVideosWatched.Type2LearnerPeriodStatsBoxToken(6, totals.TotalVideosWatched, previousTotals != null ? previousTotals.TotalVideosWatched: 0)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard learner period stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <LearnerPeriodStatsBoxToken>());
            }
        }
Beispiel #19
0
        public List <DbSubscriptionDetailToken> GetSubscriptionCancelRows(int userId, FiltersToken filter)
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var result = context.tvf_DB_GetUserSubscriptionsCancelDetails(filter.DateRange.from, filter.DateRange.to, userId, filter.CurrencyId, filter.StoreId, null, null).ToList();
                    var lines  = result.Select(x => x.DbCancelEntity2BaseOrderLineDto()).OrderByDescending(x => x.OrderNumber).ToList();

                    return(lines);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetSubscriptionCancelRows", ex, CommonEnums.LoggerObjectTypes.Dashboard);

                return(new List <DbSubscriptionDetailToken>());
            }
        }
Beispiel #20
0
        public List <DashboardKpiChartDTO> GetChartData(FiltersToken filter, int userId, bool isCompareChart)
        {
            try
            {
                var period  = Utils.ParseEnum <ReportEnums.ePeriodSelectionKinds>(filter.PeriodTypeId.ToString());
                var results = new List <DashboardKpiChartDTO>();

                var dates = PeriodKindToDateRange(period, isCompareChart);

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.tvf_FACT_GetEventsDailyLiveAggregates(dates.from, dates.to, userId, filter.StoreId).ToList();

                    var points = rows.Where(x => x.EventDate != null).GroupBy(x => new { FactDate = DateTime.Parse(x.EventDate.ToString()) }).ToArray();

                    results.AddRange(from point in points
                                     let current = point
                                                   let videoWatch = rows.FirstOrDefault(x => x.EventDate == current.Key.FactDate && x.TypeId == (int)CommonEnums.eUserEvents.VIDEO_PREVIEW_WATCH)
                                                                    let buyEntered = rows.FirstOrDefault(x => x.EventDate == current.Key.FactDate && x.TypeId == (int)CommonEnums.eUserEvents.BUY_PAGE_ENTERED)
                                                                                     let purchaseComplete = rows.FirstOrDefault(x => x.EventDate == current.Key.FactDate && x.TypeId == (int)CommonEnums.eUserEvents.PURCHASE_COMPLETE)
                                                                                                            let itemPreview = rows.FirstOrDefault(x => x.EventDate == current.Key.FactDate && x.TypeId == (int)CommonEnums.eUserEvents.COURSE_PREVIEW_ENTER)
                                                                                                                              let storeViews = rows.FirstOrDefault(x => x.EventDate == current.Key.FactDate && x.TypeId == (int)CommonEnums.eUserEvents.STORE_VIEW)
                                                                                                                                               select new DashboardKpiChartDTO
                    {
                        date = point.Key.FactDate,
                        video_preview_watch = videoWatch != null ? videoWatch.cnt : 0,
                        buy_entered         = buyEntered != null ? buyEntered.cnt : 0,
                        purchase_complete   = purchaseComplete != null ? purchaseComplete.cnt : 0,
                        items  = itemPreview != null ? itemPreview.cnt : 0,
                        stores = storeViews != null ? storeViews.cnt : 0
                    });
                }

                return(results);
            }
            catch (Exception ex)
            {
                Logger.Error("Get Dashboard Chart data", ex, CommonEnums.LoggerObjectTypes.Dashboard);
                return(new List <DashboardKpiChartDTO>());
            }
        }
        public List <SalesTotalsBoxToken> GetSalesTotals(AdminDashboardFiltersToken filter)
        {
            try
            {
                var reportPeriod = PeriodSelection2DateRange(filter.period);

                var previousPeriod = Period2Previous(filter.period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetPeriodSalesTotals(filter.currencyId, reportPeriod.from, reportPeriod.to).FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <SalesTotalsBoxToken>());
                    }

                    var rows         = context.tvf_FACT_DASH_GetPeriodSalesStats(filter.currencyId, reportPeriod.from, reportPeriod.to).FirstOrDefault();
                    var previousRows = context.tvf_FACT_DASH_GetPeriodSalesStats(filter.currencyId, previousPeriod.from, previousPeriod.to).FirstOrDefault();
                    var currency     = ActiveCurrencies.FirstOrDefault(x => x.CurrencyId == filter.currencyId);


                    var list = new List <SalesTotalsBoxToken>
                    {
                        ReportEnums.eStatsTypes.OneTimeSales.Type2SalesTotalsBoxToken(currency, 1, totals.total_onetime_sales, rows != null ? rows.total_onetime_qty  : 0, previousRows != null ? previousRows.total_onetime_qty  : 0),
                        ReportEnums.eStatsTypes.Subscription.Type2SalesTotalsBoxToken(currency, 2, totals.total_subscription_sales, rows != null ? rows.total_subscription_qty  : 0, previousRows != null ? previousRows.total_subscription_qty  : 0),
                        ReportEnums.eStatsTypes.Rental.Type2SalesTotalsBoxToken(currency, 3, totals.total_rental_sales, rows != null ? rows.total_rental_qty  : 0, previousRows != null ? previousRows.total_rental_qty  : 0),
                        ReportEnums.eStatsTypes.Free.Type2SalesTotalsBoxToken(currency, 4, 0, rows != null ? rows.total_free_qty  : 0, previousRows != null ? previousRows.total_free_qty  : 0),
                        ReportEnums.eStatsTypes.MBG.Type2SalesTotalsBoxToken(currency, 5, 0, rows != null ? rows.total_mbg_qty  : 0, previousRows != null ? previousRows.total_mbg_qty  : 0)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get sales totals stats for admin dashboard", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <SalesTotalsBoxToken>());
            }
        }
Beispiel #22
0
        public void UpdateCourseChangeLog(int courseId, out string error)
        {
            error = string.Empty;
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var courseEntity = context.Courses.SingleOrDefault(c => c.Id == courseId);

                    if (courseEntity == null)
                    {
                        error = "courseEntity not found";
                        return;
                    }

                    var entity = context.CRS_CourseChangeLog.SingleOrDefault(x => x.Uid == courseEntity.uid);

                    if (entity == null)
                    {
                        context.CRS_CourseChangeLog.Add(new CRS_CourseChangeLog
                        {
                            Uid            = courseEntity.uid
                            , LastUpdateOn = DateTime.Now
                        });
                    }
                    else
                    {
                        entity.LastUpdateOn = DateTime.Now;
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("API::Update Course log", ex, CommonEnums.LoggerObjectTypes.Course);
            }
        }
Beispiel #23
0
        public void UpdateVideosState()
        {
            try
            {
                using (var context = new lfeAuthorEntities())
                {
                    var videos = context.USER_Videos.ToList();

                    foreach (var video in videos)
                    {
                        var bcid             = video.BcIdentifier.ToString();
                        var attached2Chapter = isVideoAttached(bcid);

                        video.Attached2Chapter = attached2Chapter;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #24
0
        public int FindMissingRenditions()
        {
            var cnt = 0;
            var s3  = new S3Wrapper();

            using (var ctx = new lfeAuthorEntities())
            {
                var renditions = ctx.USER_VideosRenditions.OrderByDescending(x => x.InsertDate).ToList();

                foreach (var rend in renditions)
                {
                    var key  = rend.CloudFrontPath.Replace("https://courses-videos-prod.beame.io/", "").Replace("http://uservideos.lfe.com/", "");
                    var meta = s3.GetS3FileMetaData(key, S3_VIDEO_BUCKET_NAME);
                    if (meta == null)
                    {
                        cnt++;
                    }
                }
            }

            return(cnt);
        }
        public List <TotalsBoxToken> GetTotals(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetTotals().FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <TotalsBoxToken>());
                    }

                    var rows         = context.tvf_FACT_DASH_GetNewPeriodTotals(reportPeriod.from, reportPeriod.to).ToList();
                    var previousRows = context.tvf_FACT_DASH_GetNewPeriodTotals(previousPeriod.from, previousPeriod.to).ToList();

                    var list = new List <TotalsBoxToken>
                    {
                        ReportEnums.eStatsTypes.Stores.Type2TotalsBoxToken(1, totals.TotalStores, rows.Sum(x => x.NewStores), previousRows.Sum(x => x.NewStores)),
                        ReportEnums.eStatsTypes.Courses.Type2TotalsBoxToken(2, totals.TotalCourses, rows.Sum(x => x.NewCourses), previousRows.Sum(x => x.NewCourses)),
                        ReportEnums.eStatsTypes.Bundles.Type2TotalsBoxToken(3, totals.TotalBundles, rows.Sum(x => x.NewBundles), previousRows.Sum(x => x.NewBundles)),
                        ReportEnums.eStatsTypes.Learners.Type2TotalsBoxToken(4, totals.TotalLearners, rows.Sum(x => x.NewLearners), previousRows.Sum(x => x.NewLearners)),
                        ReportEnums.eStatsTypes.Authors.Type2TotalsBoxToken(5, totals.TotalAuthors, rows.Sum(x => x.NewAuthors), previousRows.Sum(x => x.NewAuthors))
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get totals stats for admin dashboard", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <TotalsBoxToken>());
            }
        }
        public IntegrationStatsToken GetIntegrationStatsToken(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.tvf_FACT_DASH_GetNewPeriodTotals(reportPeriod.from, reportPeriod.to).ToList();

                    return(new IntegrationStatsToken
                    {
                        TotalMailchimp = rows.Sum(x => x.NewMailchimpLists)
                        , MbgJoined = rows.Sum(x => x.NewMBGJoined)
                        , MbgCanceled = rows.Sum(x => x.MBGCancelled)
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard integration stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new IntegrationStatsToken());
            }
        }
Beispiel #27
0
        public List <PayoutCurrencySummaryDTO> GetPayoutCurrencySummaryRows(int year, int month, int?userId, short?currencyId, int executionId)
        {
            try
            {
                var list = new List <PayoutCurrencySummaryDTO>();

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.sp_PO_GetMonthlyPayoutReport(year, month, LFE_COMMISSION_PERCENT, userId, currencyId).ToList();

                    var currencies = rows.GroupBy(x => new{ x.CurrencyId, x.CurrencyName, x.ISO, x.Symbol }).Select(x => new BaseCurrencyDTO
                    {
                        CurrencyId     = x.Key.CurrencyId
                        , CurrencyName = x.Key.CurrencyName
                        , ISO          = x.Key.ISO
                        , Symbol       = x.Key.Symbol
                    }).ToList();
                    foreach (var currency in currencies)
                    {
                        var cur = currency;
                        list.Add(new PayoutCurrencySummaryDTO
                        {
                            Currency = currency
                            , Rows   = rows.Where(x => x.CurrencyId == cur.CurrencyId).Select(x => x.Entity2ReportRowDto(year, month, GetPayoutStatus(x.UserId, executionId))).OrderByDescending(x => x.TotalSales).ToList()
                        });
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("GetPayoutCurrencySummaryRows", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <PayoutCurrencySummaryDTO>());
            }
        }
Beispiel #28
0
 public void ReloadContext()
 {
     _dataContext = new lfeAuthorEntities();
 }
        public List <PlatformStatsToken> GetPlatformStats(ReportEnums.ePeriodSelectionKinds period)
        {
            var list = new List <PlatformStatsToken>();

            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.tvf_FACT_DASH_GetPlatformStats(reportPeriod.from, reportPeriod.to).ToList();

                    var previousRows = context.tvf_FACT_DASH_GetPlatformStats(previousPeriod.from, previousPeriod.to).ToList();

                    var platformIds = rows.GroupBy(x => new { id = x.RegistrationTypeId }).Select(s => s.Key.id).ToArray();

                    foreach (var platformId in platformIds)
                    {
                        var platform        = Utils.ParseEnum <CommonEnums.eRegistrationSources>(platformId.ToString());
                        var subList         = rows.Where(x => x.RegistrationTypeId == (int)platform).OrderBy(x => x.FactDate).ToList();
                        var previousSubList = previousRows.Where(x => x.RegistrationTypeId == (int)platform).ToList();


                        var token = new PlatformStatsToken
                        {
                            Platform           = platform
                            , Index            = platform.RegistrationSource2AdminDashboardIndex()
                            , Stats            = new List <PlatformStatsBoxToken>()
                            , TotalPlatformNew = subList.Sum(x => x.TotalPlatformNew)
                        };

                        token.Tendency = token.TotalPlatformNew.Value2TendencyToken(previousSubList.Sum(x => x.TotalPlatformNew));

                        #region
                        Parallel.Invoke(
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Authors
                                , Index  = 1
                                , Total  = subList[subList.Count - 1].TotalAuhtors
                                , New    = subList.Sum(x => x.NewAuthors)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewAuthors));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewAuthors
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Items
                                , Index  = 2
                                , Total  = subList[subList.Count - 1].TotalItems
                                , New    = subList.Sum(x => x.NewItems)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewItems));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewItems
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Stores
                                , Index  = 3
                                , Total  = subList[subList.Count - 1].TotalStores
                                , New    = subList.Sum(x => x.NewStores)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewStores));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewStores
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Learners
                                , Index  = 4
                                , Total  = subList[subList.Count - 1].TotalLearners
                                , New    = subList.Sum(x => x.NewLearners)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewLearners));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewLearners
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Sales
                                , Index  = 5
                                , Total  = subList[subList.Count - 1].TotalSales
                                , New    = subList.Sum(x => x.NewSales)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewSales));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewSales
                                });
                            }

                            token.Stats.Add(box);
                        });
                        #endregion

                        list.Add(token);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("Get platform stats for admin dashboard", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(list);
            }
        }
Beispiel #30
0
        public DashboardEventToken GetDashboardEventToken(int userId, DashboardEnums.eDbEventTypes type, DateRangeToken dates, string eventName = null)
        {
            var token = new DashboardEventToken
            {
                Uid        = Guid.NewGuid()
                , Type     = type
                , Name     = eventName ?? Utils.GetEnumDescription(type)
                , Color    = type.EventType2Color()
                , Enabled  = true
                , IsStatic = false
            };

            if (type == DashboardEnums.eDbEventTypes.Custom || type == DashboardEnums.eDbEventTypes.NewMailchimp)
            {
                return(token);
            }

            token.IsStatic = true;

            using (var context = new lfeAuthorEntities())
            {
                var evenStats = context.tvf_DB_GetAuthorEventStats(userId).FirstOrDefault();

                if (evenStats == null)
                {
                    return(token);
                }

                DateTime?date = null;

                switch (type)
                {
                case DashboardEnums.eDbEventTypes.NewItem:
                    var cd = evenStats.LastCoursePublish;
                    var bd = evenStats.LastBundlePublish;

                    if (cd == null && bd == null)
                    {
                        return(token);
                    }

                    date = (cd ?? DateTime.MinValue).CompareToDate(bd ?? DateTime.MinValue);
                    break;

                case DashboardEnums.eDbEventTypes.NewChapter:
                    date = evenStats.LastChaperCreated;
                    break;

                case DashboardEnums.eDbEventTypes.NewFbStore:
                    date = evenStats.LastChaperCreated;
                    break;

                case DashboardEnums.eDbEventTypes.NewStore:
                    date = evenStats.LastChaperCreated;
                    break;
                }

                token.Date    = date;
                token.Enabled = date != null && (((DateTime)date).Ticks >= dates.from.Ticks && ((DateTime)date).Ticks <= dates.to.Ticks);

                return(token);
            }
        }