public static Earning ToModelToEntity(this EarningModel model) { var earning = new Earning { ListItemsEarning = model.ListItemsEarningModel.Select(x => x.ModelToEntity()) }; return(earning); }
public static double SumEarning(this EarningModel model) { double sumEarning = 0; foreach (ItemModel item in model.ListItemsEarningModel) { sumEarning += item.HowMuch; } return(sumEarning); }
public ActionResult Earnings() { var model = new EarningModel(); var customer = _customerService.GetCustomerId(this.CustomerId); var commission = customer.GetCustomerAttributeValue <decimal>(CustomerAttributeNames.Commission); model.CustomerId = customer.Id; model.Commission = commission; var dateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var dateEnd = DateTime.Now.AddMonths(1).AddDays(-1); var applies = _applyCashService.GetAllApplyCashs(createdFrom: dateStart, createdTo: dateEnd, customerId: this.CustomerId, audit: (int)AuditStatus.Audited); model.CurrentWithdrawalAmount = applies.Items.Sum(a => a.Amount); model.CurrentWithdrawals = applies.TotalCount; var comms = _commissionServicer.GetAllCommissions(customerId: this.CustomerId, createdFrom: dateStart, createdTo: dateEnd); model.CurrentCommissionCount = comms.TotalCount; model.CurrentCommissionAmount = comms.Items.Sum(c => c.ReturnAmount); return(View(model)); }
public void WhenWantSaveThenSubtotalAreEsqualsThatHisList() { var context = new MonthFinanceContextMock(); //create Model with properties. var earningModel = new EarningModel { ListItemsEarningModel = new List <ItemModel> { new ItemModel { Name = "Salary", HowMuch = 5000 } } }; var expenseModel = new ExpensesModel { ListItemsExpenseModel = new List <ItemModel> { new ItemModel { Name = "Rent House Dublin", HowMuch = 2500 } } }; var monthFinanceEntity = new MonthFinanceModel { Expense = expenseModel, //EarningModel = earningModel, Saving = 1000 }; var entity = monthFinanceEntity.ToModelToEntity(); //entity.SubTotalEarning = 5000; //entity.SubTotalExpense = 2500; //pass model to ententy var result = context.Save(entity); Assert.Equal(true, result); }