Beispiel #1
0
        public ActionResult ExportSubscribers(int?id = null)
        {
            var list = BaseAuthorServices.GetAuthorSubscribers(CurrentUserId, id).OrderBy(x => x.name).ToList();

            var output = new MemoryStream();
            var writer = new StreamWriter(output, Encoding.UTF8);

            writer.Write("Name,");
            writer.Write("Email");

            writer.WriteLine();

            foreach (var subscriber in list)
            {
                writer.Write(subscriber.name);
                writer.Write(",");
                writer.Write("\"");
                writer.Write(subscriber.email);
                writer.Write("\"");
                writer.WriteLine();
            }

            writer.Flush();
            output.Position = 0;

            string fileName;

            if (id == null)
            {
                fileName = (TodayFileString() + "_" + this.CurrentUser().Nickname + "_subscribers.csv").OptimizedUrl();
            }
            else
            {
                var course = _courseServices.GetCourseEditDTO((int)id);

                fileName = (TodayFileString() + "_" + course.CourseName + "_" + this.CurrentUser().Nickname + "_subscribers.csv").OptimizedUrl();
            }

            return(File(output, "text/comma-separated-values", fileName));
        }
Beispiel #2
0
        public ActionResult GetAuthorSubscribers([DataSourceRequest] DataSourceRequest request, int?courseId = null)
        {
            var list = BaseAuthorServices.GetAuthorSubscribers(CurrentUserId, courseId);

            return(Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }