public ActionResult DirectBannerPrices(int?companyId, long?bannerId, string token) { var model = new DirectBannerPricesVM { BannerId = bannerId, Token = token ?? Session[YandexAuthService.SessionKey].NotNullString() }; var service = token.IsEmpty() ? DirectApiService : new DirectApiService(token: token); if (companyId.HasValue) { var bannerIds = service.GetActiveBanners( new GetBannersInfo { CampaignIDS = new[] { companyId.Value } }).Select(x => x.BannerID).ToArray(); var prices = service.GetBannerPhrases(bannerIds).ToList(); var data = prices.Select(x => _.List(x.BannerID.ToString(), x.Price.ToString(), (x.Prices.ToList().Select((price, i) => Tuple.Create(i + 1, price < x.Price)) .FirstOrDefault(y => y.Item2).GetOrDefault(y => y.Item1)).ToString(), x.Phrase) .AddFluent(x.Prices.Select(z => z.ToString())) ); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(data)), "text/csv", "bannerprices.csv")); } if (bannerId.HasValue) { model.Prices = service.GetBannerPhrases(new[] { bannerId.Value }).ToList(); } return(View(model)); }
public ActionResult SpecialistOrders(string text) { if (System.Web.HttpContext.Current.Request.IsPost()) { var sigIds = Regex.Split(text, @"[^\d]").Where(x => !x.IsEmpty()).Select(decimal.Parse).ToList(); var sources = SourceService.GetAll().Select(x => new { x.Source_ID, x.Name }) .ToDictionary(x => x.Source_ID, x => x.Name); var result = sigIds.GetRows(1000).SelectMany(ids => OrderDetailService.GetAll(x => ids.Contains(x.StudentInGroup_ID.Value)) .Select(x => new{ x.OrderID, x.StudentInGroup_ID }).ToList()) .ToDictionary(x => x.StudentInGroup_ID, x => x.OrderID); var sigs = sigIds.GetRows(1000).SelectMany(ids => StudentInGroupService.GetAll(x => ids.Contains(x.StudentInGroup_ID)) .Select(x => new { x.StudentInGroup_ID, x.StudentInGroupSources }).ToList() ).Select(x => _.List(x.StudentInGroup_ID.ToString(), result.GetValueOrDefault(x.StudentInGroup_ID).NotNullString() ?? x.StudentInGroupSources.Select(y => y.Source_ID).ToList().Select(y => sources[y]).FirstOrDefault())); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(sigs)), "text/csv", "SpecialistOrders.csv")); } return(View()); }
public string Csv(UrlHelper urlHelper) { _url = urlHelper; var coursesData = GetCoursesData(); return(CsvUtil.Render(coursesData)); }
public void CreateFile() { var users = new VkontakteService(VkontakteService.Token).UsersSearch(); var data = CsvUtil.Render(users); File.WriteAllText("topusers.csv", data); }
public ActionResult DownloadResults(int id) { UserTestService.LoadWith(x => x.User, x => x.Test); var userTests = _.List(GetUserTests(id, false)); var data = UserTestResultService.GetResultData(userTests); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(data)), "text/csv", "TestResults-{0}.csv".FormatWith(id))); }
public ActionResult TestResults() { UserTestService.LoadWith(x => x.User, x => x.Test); var testIds = _.List(707, 706, 708, 705); var userTests = UserTestService.GetAll(x => testIds.Contains(x.TestId)).ToList(); var data = UserTestResultService.GetResultData(_.List(userTests)); return(File(Encoding.GetEncoding(1251).GetBytes(CsvUtil.Render(data)), "text/csv", "TestResults.csv")); }
public ActionResult DownloadResult(int groupInfoId) { List <int> userIds; var groupInfo = GetGroupInfo(groupInfoId, out userIds); UserTestService.LoadWith(x => x.User, x => x.Test); var userTests = groupInfo.GroupTests.Select(gt => UserTestService.GetUserTests(gt) .Where(x => userIds.Contains(x.UserId)).ToList()).ToList(); var data = UserTestResultService.GetResultData(userTests); return(File(Encoding.GetEncoding(1251).GetBytes(CsvUtil.Render(data)), "text/csv", "GroupResults-{0}.csv".FormatWith(groupInfo.Group_ID))); }
public ActionResult GroupFreePlaces() { var dateEnd = DateTime.Today.AddDays(14); var courses = GroupService.GetAll().PlannedAndNotBegin() .Where(x => x.DateBeg < dateEnd && CourseDirections.Motorina.Contains(x.Course.CourseDirectionA_TC)) .Select(x => new { x.Course_TC, Free = x.MaxNumOfStudents - x.GroupCalc.NumOfStudents }).ToList().OrderByDescending(x => x.Free).Select(x => _.List(x.Course_TC, x.Free.ToString())); var result = CsvUtil.Render(courses); return(File(Encoding.UTF8.GetBytes(result), "text/csv", "freeplaces-{0}.csv".FormatWith(DateTime.Today.DefaultString()))); }
public string Get(UrlHelper urlHelper) { _url = urlHelper; var data = Goods(); data.Insert(0, _.List( "Program ID", "Program name", "Destination URL", "Thumbnail image URL", "Image URL", "Program description", "School name", "Contextual keywords" )); return(CsvUtil.Render(data, ",")); }
public ActionResult UserEmails(string text, string courseTC) { if (System.Web.HttpContext.Current.Request.IsPost()) { var userIds = Regex.Split(text, @"[^\d]").Where(x => !x.IsEmpty()).Select(int.Parse).ToList(); var usersWithOrders = OrderService.GetAll(x => x.UpdateDate >= DateTime.Today.AddDays(-7) && userIds.Contains(x.UserID.Value) && !x.PaymentType_TC.Equals(null)).Select(x => x.UserID.Value).ToList(); userIds = userIds.Except(usersWithOrders).ToList(); userIds = FilterUsersByCourse(userIds, courseTC); var result = UserService.GetAll(x => userIds.Contains(x.UserID)).ToList(); var data = result.Select(x => _.List(x.Email)).ToList(); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(data)), "text/csv", "emails.csv")); } return(View()); }
public ActionResult PaidOrders(string text) { if (System.Web.HttpContext.Current.Request.IsPost()) { var orderIds = Regex.Split(text, @"[^\d]").Where(x => !x.IsEmpty()).Select(decimal.Parse).ToList(); var result = orderIds.GetRows(1000).SelectMany(ids => OrderDetailService.GetAll(x => ids.Contains(x.OrderID.Value)).Where(x => BerthTypes.PaidReport.Contains( x.StudentInGroup.BerthType_TC)) .Select(x => new{ x.OrderID, x.StudentInGroup.BerthType_TC }).ToList() .GroupBy(x => x.OrderID) .Select(x => new { x.Key, BerthType = x.Select(y => y.BerthType_TC).Max() }).ToList()).Select(x => _.List(x.Key.ToString(), x.BerthType)).ToList(); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(result)), "text/csv", "PaidOrders.csv")); } return(View()); }
public void Write() { var courseTCs = Courses.Select(x => x.Key).ToList(); var context = new SpecialistDataContext(); var courseData = context.Courses.Select(x => new { x.Course_TC, x.UrlName }) .ToDictionary(x => x.Course_TC, x => x.UrlName); var groups = context.Groups.Where(x => courseTCs.Contains(x.Course_TC)).NotBegin() .Where(x => x.DateEnd != null) .Select(x => new { x.Course_TC, x.DateBeg, x.DateEnd, x.TimeBeg, x.TimeEnd }).OrderBy(x => x.DateBeg).ToList(); var data = new List <List <string> >(); foreach (var gr in groups) { var en = new CultureInfo("en-US"); var row = _.List( Courses[gr.Course_TC.Trim()].ToString(), "Russian", "RUS", "MOSKVA", "GOSPITALNY LANE 4/6 ", "MOSKVA", "MOSKVA", "105005", gr.DateBeg.Value.ToString("dd-MMM-yyyy", en), gr.DateEnd.Value.ToString("dd-MMM-yyyy", en), "ILT", "", "http://www.specialist.ru/course/" + courseData[gr.Course_TC.Trim()], "+7 (495)7804848", "", "*****@*****.**", "57017"); data.Add(row); } File.WriteAllText("cisco.csv", CsvUtil.Render(data)); }
public ActionResult DownloadOrders() { var data = GetOrgSig().Where(x => x.Charge > 0).Select(x => new { x.Group.DateBeg, x.Group.DateEnd, x.Student.FirstName, x.Student.LastName, x.Student.MiddleName, x.Group.Course.WebName, x.Charge }).ToList().OrderByDescending(x => x.DateBeg).Select(x => _.List( x.DateBeg.DefaultString(), x.DateEnd.DefaultString(), x.LastName, x.FirstName, x.MiddleName, x.WebName, ((int)x.Charge).ToString() )).ToList(); data.Insert(0, _.List("Дата начала", "Дата окончания", "Фамилия", "Имя", "Отчество", "Курс", "Стоимость")); return(File(StringUtils.Encoding1251.GetBytes(CsvUtil.Render(data)), "text/csv", "orders.csv")); }
public string GetCsv() { var allPrices = PriceViewService.GetAll(x => x.Track_TC == null).ToList() .GroupByToDictionary(x => x.Course_TC, x => x); var allGroups = GroupService.GetAll().PlannedAndNotBegin() .Where(x => x.Color_TC == Colors.Yellow && x.Course.IsActive) .OrderBy(x => x.DateBeg).ToList().GroupByToDictionary(x => x.Course_TC, x => x); var result = new List <List <string> >(); CourseService.LoadWith(x => x.CourseContents, x => x.AuthorizationType); var courses = CourseService.GetAll().Where(x => x.IsActive && !CourseTC.HalfTrackCourses.Contains(x.Course_TC) && !x.IsTrack.Value).OrderBy(x => x.Course_ID).ToList(); foreach (var course in courses) { var courseTC = course.Course_TC; var row = new List <string>(); var prices = allPrices.GetValueOrDefault(courseTC) ?? new List <PriceView>(); var isWebinar = GetPrice(PriceTypes.Webinar, prices) > 0; var groupList = allGroups.GetValueOrDefault(courseTC) ?? new List <Group>(); row.Add(courseTC); row.Add(course.Name); row.Add(((int)course.BaseHours) + " ак.ч."); row.Add(course.AuthorizationType.GetOrDefault(x => x.AuthorizationName)); row.Add(course.IsProjectAllowed ? "П" : ""); row.Add(isWebinar ? "В" : ""); var description = course.Description; row.Add(ClearnText(description)); var prerequisete = course.CoursePrerequisites.Select( x => (x.Text + " " + x.RequiredCourse.GetOrDefault(z => z.Name)).Trim()).Where(x => x != null).JoinWith(";"); row.Add(ClearnText(prerequisete)); row.Add(ClearnText(course.OnComplete)); var contents = course.CourseContents.OrderBy(x => x.ModuleNumber) .Select(x => "Модуль " + x.ModuleNumber + ". " + x.ModuleName) .JoinWith(";"); row.Add(ClearnText(contents)); Func <string, bool> addPrice = type => { var price = GetPrice(type, prices); if (type == PriceTypes.PrivatePersonWeekend) { var discount = NearestGroupSet.HasMorningDiscount(groupList); var morningPrice = discount.HasValue ? OrderDetail.FloorToFifty( (price * (100 - discount.Value)) / 100) : price; row.Add(morningPrice > 0 ? morningPrice.ToString() : ""); } row.Add(price > 0 ? ((int)price).ToString() : ""); return(price > 0); }; var types = _.List(PriceTypes.PrivatePersonWeekend, PriceTypes.Corporate); var hasPrice = false; foreach (var prefix in _.List("")) { foreach (var type in types) { hasPrice |= addPrice(prefix + type); } } addPrice(PriceTypes.Webinar); if (hasPrice) { var groups = groupList .Select(DateInterval).Distinct().JoinWith(" "); row.Add(groups); row.Add(groupList.Any(x => x.IsOpenLearning) ? "О" : ""); var certs = new CourseVM { Course = course } .Certificates.Select(x => x.Name) .JoinWith(";"); row.Add(certs); result.Add(row); } } var csv = result.Select(x => x.Select(y => y .GetOrDefault(z => z.Replace('\t', ' ').Trim()))); return(CsvUtil.Render(csv)); }