public void Create_Formula_That_Not_Exist() { List <FormulaName> formulaNames = CalculationFormulaFactory.GetAll(); IFormula formula = CalculationFormulaFactory.Create(FormulaType.AreaBased); Assert.IsNotNull(formula, "formala is created"); }
public Task <IEnumerable <Expens> > GetAllByDateAsync(DateTime from, DateTime to) { var expenses = _dbContext.Expenses.Where(x => x.From >= from && x.To <= to).ToList(); //Load All Categories, foreach (var item in expenses) { //Find realated category var formulaName = "";// From related category item.Formula = CalculationFormulaFactory.Create(formulaName); } return(null); }
public async Task <IEnumerable <ChargeExpense> > GetChargeExpenseAsync(DateTime from, DateTime to) { var expenses = await _baseInfoContext.ExpenseInfos.Where(e => e.From < to && e.To >= from) .Include(e => e.ExpenseCategory) .ToListAsync(); return(expenses.Select(e => { var chargeExpense = e.ToChargExpense(); chargeExpense.Formula = CalculationFormulaFactory.Create(chargeExpense.FormulaType); return chargeExpense; })); }
public async Task CalculateChargeAsync(int chargeId) { var calculationInfos = await GetExpensesAsync(chargeId); List <ChargeItemDTO> chargeItems = new List <ChargeItemDTO>(); foreach (var calculationInfo in calculationInfos) { var shareInfos = await GetShareInfosAsync(calculationInfo); IFormula formula = CalculationFormulaFactory.Create(calculationInfo.FormulaName); chargeItems.AddRange(formula.Calculate(calculationInfo.Amount, shareInfos, calculationInfo.ExpenseId, calculationInfo.IsForOwner)); } var gateway = _gatewayFactory.CreateChargeItemTableGateway(); await gateway.InsertChargeItemsAsync(chargeItems, chargeId); }
static async Task Main(string[] args) { //autoResetEvent = new AutoResetEvent(false); //Console.WriteLine("Hello World!"); ////Thread myWorker1 = new Thread(() => DoMyFirstJob()); ////myWorker1Start(); ////Thread myWorker2 = new Thread(() => DoMySecondJob()); ////myWorker2.Start(); //Console.WriteLine($"Main thread id { Thread.CurrentThread.ManagedThreadId} "); //var task1 = Task.Run(DoMyFirstJob); //var task2 = Task.Run(DoMySecondJob); //await Task.WhenAll(task1, task2); //var connectionString = ConfigurationManager.ConnectionStrings["AppartmentManagementCNX"].ConnectionString; //var baseInfoService = new BaseInfoApplicationService(connectionString); //var units = await baseInfoService.GetAllOwnerTenantByUnitId(1); #region EF IEnumerable <Student> students = null; //using (var dbContext = new StudentDbContext()) //{ // students = dbContext.Students.Where(x => x.Name == "Ali").ToList(); // /*OK=> var dateTime = new DateTime(1900, 1, 1); // * students = dbContext.Students.Where(x => x.BirthDate > dateTime).ToList(); // */ // // OK=> students = dbContext.Students.Where(x => x.BirthDate.Year > 1900).ToList(); // //Don't do this => students = dbContext.Students.Where(x=> IsBithYearGraterThan(x.BirthDate.Year,1900)).ToList(); //} //foreach (var item in students) //{ // Console.WriteLine($"{item.Id}. {item.Name}"); //} //using (var dbContext = new StudentDbContext()) //{ // var s = new Student { Name = "Nima", BirthDate = new DateTime(2007, 08, 09) }; // dbContext.Students.Add(s); // dbContext.SaveChanges(); //} //using (var dbContext = new StudentDbContext()) //{ // var s = dbContext.Students.FirstOrDefault(x => x.Id == 1); // if (s != null) // { // s.Name = "Nima"; // } // dbContext.SaveChanges(); //} //using (var dbContext = new StudentDbContext()) //{ // var s = new Student { Id = 1 }; // dbContext.Students.Remove(s); // dbContext.SaveChanges(); //} //var s = new Student { Name = "Nima", BirthDate = new DateTime(2007, 08, 09), Id = 2 }; //using (var dbContext = new StudentDbContext()) //{ // dbContext.Attach<Student>(s); // s.Name = "Hosein"; // dbContext.SaveChanges(); //} //var s = new Student { Id = 2}; //using (var dbContext = new StudentDbContext()) //{ // dbContext.Students.Remove(s); // dbContext.SaveChanges(); //} //using (var dbContext = new StudentDbContext()) //{ // var s1 = new Student { Id = 7 }; // var s2 = new Student { Id = 3 }; // dbContext.Attach<Student>(s1); // dbContext.Attach<Student>(s2); // s1.BirthDate = new DateTime(2000, 1, 1); // s2.BirthDate = new DateTime(2001, 1, 1); // dbContext.SaveChanges(); //} //using (var dbContext = new StudentDbContext()) //{ // var s1 = new Student { Id = 7 }; // var s2 = new Student { Id = 3 }; // //dbContext.Students.RemoveRange(new Student[] { s1, s2 }); // dbContext.Students.RemoveRange(s1, s2); // dbContext.SaveChanges(); //} //Teacher t = null; //using (var dbContext = new StudentDbContext()) //{ // //Eager Loading // // var teacher = dbContext.Teachers.Include(x => x.Students).FirstOrDefault(); // //Explicit Loading // //var teacher = dbContext.Teachers.FirstOrDefault(); // //dbContext.Entry(teacher).Collection(x => x.Students).Load(); // //Lazy Loading // //var teacher = dbContext.Teachers.FirstOrDefault(); // //Console.WriteLine(teacher.Students.Count); // t = dbContext.Teachers.FirstOrDefault(); //} //using (var dbContext = new StudentDbContext()) //{ // var studentsList = dbContext.Students.ToList(); //} //Console.WriteLine(t.Students.Count); #endregion EF #region params //var a = Add(1, 2, 3); //var b = Add(1); //var c = Add(); //var d = Add(new int[] { 1,2,3,4,5}); #endregion params #region Reflection var formulaNames = CalculationFormulaFactory.GetAll(); var formula = CalculationFormulaFactory.Create(formulaNames[0].TypeName); var share = formula.Calculate(null, null, 1); #endregion Reflection Console.WriteLine("Done"); Console.ReadLine(); }