public ActionResult ListBonusPromotion(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            IQueryable <UserProfile> items = models.GetTable <UserProfile>();

            viewModel.UserName = viewModel.UserName.GetEfficientString();
            if (viewModel.UserName != null)
            {
                items = items.Where(c => c.RealName.Contains(viewModel.UserName) || c.Nickname.Contains(viewModel.UserName));
            }

            if (viewModel.ActorID.HasValue)
            {
                items = items
                        .Join(models.GetTable <LearnerFitnessAdvisor>()
                              .Where(f => f.CoachID == viewModel.ActorID),
                              u => u.UID, f => f.UID, (u, f) => u);
            }

            var taskItems = models.GetTable <PDQTask>()
                            .Join(models.GetTable <PDQTaskBonus>(),
                                  t => t.TaskID, q => q.TaskID, (t, q) => t)
                            .Join(items, t => t.UID, u => u.UID, (t, u) => t);

            return(View("~/Views/Report/Module/ListBonusPromotion.ascx", taskItems));
        }
Пример #2
0
        public async Task <ActionResult> CreateBonusCreditXlsxAsync(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            var taskItems = models.GetTable <PDQTask>()
                            .Join(models.GetTable <PDQTaskBonus>(),
                                  t => t.TaskID, q => q.TaskID, (t, q) => t)
                            .Select(t => t.UID);


            IQueryable <UserProfile> items = models.GetTable <UserProfile>().Where(u => taskItems.Contains(u.UID));

            if (items.Count() == 0)
            {
                Response.Cookies.Append("fileDownloadToken", viewModel.FileDownloadToken ?? "");
                return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "資料不存在!!"));
            }

            var details = items
                          .Select(i => new
            {
                姓名          = i.FullName(true),
                目前Beyond幣金額 = i.BonusPoint(models),
            });


            Response.Cookies.Append("fileDownloadToken", viewModel.FileDownloadToken ?? "");
            Response.Headers.Add("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.Headers.Add("Content-Disposition", String.Format("attachment;filename={0}({1:yyyy-MM-dd HH-mm-ss}).xlsx", HttpUtility.UrlEncode("BonusAccumulation"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                DataTable table = details.ToDataTable();
                table.TableName = $"截至 {DateTime.Today:yyyyMMdd} Beyond幣金額";

                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    String tmpPath = Path.Combine(FileLogger.Logger.LogDailyPath, $"{DateTime.Now.Ticks}.tmp");
                    using (FileStream tmp = System.IO.File.Create(tmpPath))
                    {
                        xls.SaveAs(tmp);
                        tmp.Flush();
                        tmp.Position = 0;

                        await tmp.CopyToAsync(Response.Body);
                    }
                    await Response.Body.FlushAsync();

                    System.IO.File.Delete(tmpPath);
                }
            }

            return(new EmptyResult());
        }
Пример #3
0
        public ActionResult CreateBonusCreditXlsx(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            var taskItems = models.GetTable <PDQTask>()
                            .Join(models.GetTable <PDQTaskBonus>(),
                                  t => t.TaskID, q => q.TaskID, (t, q) => t)
                            .Select(t => t.UID);


            IQueryable <UserProfile> items = models.GetTable <UserProfile>().Where(u => taskItems.Contains(u.UID));

            if (items.Count() == 0)
            {
                Response.AppendCookie(new HttpCookie("fileDownloadToken", viewModel.FileDownloadToken));
                return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "資料不存在!!"));
            }

            var details = items
                          .Select(i => new
            {
                姓名          = i.FullName(true),
                目前Beyond幣金額 = i.BonusPoint(models),
            });


            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AppendCookie(new HttpCookie("fileDownloadToken", viewModel.FileDownloadToken));
            Response.AddHeader("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}({1:yyyy-MM-dd HH-mm-ss}).xlsx", HttpUtility.UrlEncode("BonusAccumulation"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                DataTable table = details.ToDataTable();
                table.TableName = $"截至 {DateTime.Today:yyyyMMdd} Beyond幣金額";

                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    xls.SaveAs(Response.OutputStream);
                }
            }

            return(new EmptyResult());
        }
        public ActionResult ListLearnerBonus(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            if (viewModel.KeyID != null)
            {
                viewModel.UID = viewModel.DecryptKeyValue();
            }

            var taskItems = models.GetTable <PDQTask>()
                            .Where(t => t.UID == viewModel.UID)
                            .Join(models.GetTable <PDQTaskBonus>(),
                                  t => t.TaskID, q => q.TaskID, (t, q) => t);

            return(View("~/Views/Report/Module/ListLearnerBonus.ascx", taskItems));
        }
        public ActionResult ListBonusAward(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            IQueryable <LearnerAward> items = models.GetTable <LearnerAward>();

            Expression <Func <LearnerAward, bool> > queryExpr = c => false;
            bool hasConditon = false;

            viewModel.UserName = viewModel.UserName.GetEfficientString();
            if (viewModel.UserName != null)
            {
                hasConditon = true;
                queryExpr   = queryExpr.Or(c => c.UserProfile.RealName.Contains(viewModel.UserName) || c.UserProfile.Nickname.Contains(viewModel.UserName));
            }

            if (viewModel.ActorID.HasValue)
            {
                hasConditon = true;
                queryExpr   = queryExpr.Or(c => c.ActorID == viewModel.ActorID);
            }

            if (viewModel.ItemID.HasValue)
            {
                hasConditon = true;
                queryExpr   = queryExpr.Or(c => c.ItemID == viewModel.ItemID);
            }

            if (hasConditon)
            {
                items = items.Where(queryExpr);
            }

            if (viewModel.DateFrom.HasValue)
            {
                items = items.Where(c => c.AwardDate >= viewModel.DateFrom);
            }

            if (viewModel.DateTo.HasValue)
            {
                items = items.Where(c => c.AwardDate < viewModel.DateTo.Value.AddDays(1));
            }

            return(View("~/Views/Report/Module/ListBonusAward.ascx", items));
        }
Пример #6
0
        public async Task <ActionResult> CreateBonusAwardXlsxAsync(AwardQueryViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            IQueryable <LearnerAward> items = models.GetTable <LearnerAward>();

            if (viewModel.ItemID.HasValue)
            {
                items = items.Where(a => a.ItemID == viewModel.ItemID);
            }

            if (items.Count() == 0)
            {
                Response.Cookies.Append("fileDownloadToken", viewModel.FileDownloadToken ?? "");
                return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "資料不存在!!"));
            }


            var details = items.ToArray()
                          .Select(item => new
            {
                兌換時間 = String.Format("{0:yyyyMMdd}", item.AwardDate),
                姓名   = item.Actor.FullName(true),
                兌換場所 = models.GetTable <CoachWorkplace>().Where(c => c.CoachID == item.ActorID)
                       .Select(c => c.BranchStore.BranchName).FirstOrDefault(),
                兌換人員 = item.Actor.FullName(false),
                兌換商品 = item.BonusAwardingItem.ItemName,
                使用日期 = item.BonusAwardingItem.BonusAwardingLesson != null
                        ? item.AwardingLesson != null
                            ? item.AwardingLesson.RegisterLesson.LessonTime.Count > 0
                                ? String.Format("{0:yyyyMMdd}", item.AwardingLesson.RegisterLesson.LessonTime.First().ClassTime)
                                : ""
                            : item.AwardingLessonGift.RegisterLesson.LessonTime.Count > 0
                                ? String.Format("{0:yyyyMMdd}", item.AwardingLessonGift.RegisterLesson.LessonTime.First().ClassTime)
                                : ""
                        : "",
                贈與學員 = item.AwardingLessonGift != null ? item.AwardingLessonGift.RegisterLesson.UserProfile.FullName(true) : "",
            });

            Response.Cookies.Append("fileDownloadToken", viewModel.FileDownloadToken ?? "");
            Response.Headers.Add("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.Headers.Add("Content-Disposition", String.Format("attachment;filename={0}({1:yyyy-MM-dd HH-mm-ss}).xlsx", HttpUtility.UrlEncode("BonusAward"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                DataTable table = details.ToDataTable();
                table.TableName = $"截至 {DateTime.Today:yyyyMMdd} 兌換商品";

                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    String tmpPath = Path.Combine(FileLogger.Logger.LogDailyPath, $"{DateTime.Now.Ticks}.tmp");
                    using (FileStream tmp = System.IO.File.Create(tmpPath))
                    {
                        xls.SaveAs(tmp);
                        tmp.Flush();
                        tmp.Position = 0;

                        await tmp.CopyToAsync(Response.Body);
                    }
                    await Response.Body.FlushAsync();

                    System.IO.File.Delete(tmpPath);
                }
            }

            return(new EmptyResult());
        }