Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
nik
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // var numEntity var numDays = 7; var numMonths = 12; // This DateTimeOffset will be passed through method from FE var parameterStartDay = DateTimeOffset.Now; // The start of the current WEEK DateTimeOffset startOfLastWeek = new DateTimeOffset(new DateTime(parameterStartDay.Year, parameterStartDay.Month, parameterStartDay.Day - 7)); List<CampaignCostEntity> dayListCosts = new List<CampaignCostEntity>(); for (int i = 0; i <= 7; i++) { //float dayTotalCost = Context.Set<Campaign>().Where(x => x.CreatedAt >= startOfLastWeek.AddDays(i) && x.CreatedAt < startOfLastWeek.AddDays(i + 1) && x.CompanyID == shardKey && x.Sent == true && x.Deleted == false).Sum(x => x.Cost); //dayListCosts.Add(new CampaignCostEntity() { Name = startOfLastWeek.AddDays(i).DayOfWeek.ToString(), CampaignCost = dayTotalCost }); dayListCosts.Add(new CampaignCostEntity(){ Name = startOfLastWeek.AddDays(i).DayOfWeek.ToString(), CampaignCost = 1579 }); } foreach (CampaignCostEntity combo in dayListCosts) Console.WriteLine(combo.Name + " " + combo.CampaignCost); // The start of the current MONTH DateTimeOffset startOfLastMonth = new DateTimeOffset(new DateTime(parameterStartDay.Year, parameterStartDay.Month - 1, parameterStartDay.Day)); List<CampaignCostEntity> monthListCosts = new List<CampaignCostEntity>(); for (int i = 0; i <= 31; i++) { //float dayTotalCost = Context.Set<Campaign>().Where(x => x.CreatedAt >= startOfLastMonth.AddDays(i) && x.CreatedAt < startOfLastMonth.AddDays(i + 1) && x.CompanyID == shardKey && x.Sent == true && x.Deleted == false).Sum(x => x.Cost); //monthListCosts.Add(new CampaignCostEntity() { Name = startOfLastMonth.AddDays(i).Date.ToString().Substring(0, 5), CampaignCost = dayTotalCost }); monthListCosts.Add(new CampaignCostEntity(){ Name = startOfLastMonth.AddDays(i).Date.ToString().Substring(0, 5), CampaignCost = 1579 }); } foreach (CampaignCostEntity combo in monthListCosts) Console.WriteLine(combo.Name + " " + combo.CampaignCost); // The start of the current YEAR DateTimeOffset startOfLastYear = new DateTimeOffset(new DateTime(parameterStartDay.Year - 1, parameterStartDay.Month, parameterStartDay.Day)); List<CampaignCostEntity> yearListCosts = new List<CampaignCostEntity>(); for (int i = 0; i <= 12; i++) { //float dayTotalCost = Context.Set<Campaign>().Where(x => x.CreatedAt >= startOfLastYear.AddMonths(i) && x.CreatedAt < startOfLastYear.AddMonths(i + 1) && x.CompanyID == shardKey && x.Sent == true && x.Deleted == false).Sum(x => x.Cost); //yearListCosts.Add(new CampaignCostEntity() { Name = startOfLastYear.AddMonths(i).Month.ToString(), CampaignCost = dayTotalCost }); yearListCosts.Add(new CampaignCostEntity(){ Name = startOfLastYear.AddMonths(i).Month.ToString(), CampaignCost = 1579 }); } foreach (CampaignCostEntity combo in yearListCosts) Console.WriteLine(combo.Name + " " + combo.CampaignCost); Console.WriteLine("Last week starts from: " + startOfLastWeek); Console.WriteLine(); Console.WriteLine("Last month starts from: " + startOfLastMonth); Console.WriteLine(); Console.WriteLine("Last year starts from: " + startOfLastYear); Console.WriteLine(); Console.WriteLine( startOfLastWeek.ToString( "dddd" ) ); Console.WriteLine( startOfLastWeek.AddDays( 1 )); } public class CampaignCostEntity { public string Name { get; set; } public float CampaignCost { get; set; } } } }
run
|
edit
|
history
|
help
0
Find longest span of characters in string
The Fisher–Yates shuffle array extension method
sdrfgthyuytgrfdwcd
Found many section of times intersect.
Number to string
C# - a method that accepts an indefinite number of parameters
problem
12
New easy way to start lightweight threads
sdfrgthyjui65trfvf