コード例 #1
0
        private static void AddTaxToGirl(string firstname, string lastname, int tax)
        {
            var girlRepo = new GenericRepository<Girl>(new GirlsAgencyContext());
            var girl = girlRepo.Search(g => g.FirstName == firstname && g.LastName == lastname).FirstOrDefault();

            if (girl == null)
            {
                throw new ApplicationException("Girl does not exists/found");
            }

            var girlTaxes = new GirlsTaxesEntities();

            string girlFullName = girl.FirstName + " " + girl.LastName;

            var girlTax = GetAssignTax(girlFullName, girlTaxes);

            if (girlTax == null)
            {
                girlTaxes.GirlsTaxes.Add(new GirlsTax
                {
                    GirlName = girlFullName,
                    Tax = tax
                });
            }
            else
            {
                girlTax.Tax = tax;
            }

            girlTaxes.SaveChanges();
        }
コード例 #2
0
 private static GirlsTax GetAssignTax(string fullName, GirlsTaxesEntities ctx)
 {
     return ctx.GirlsTaxes.FirstOrDefault(n => n.GirlName == fullName);
 }
コード例 #3
0
        private static string[][] GetData()
        {
            // var db = new SQLiteDatabase(@"..\..\ProductsTaxes.sqlite");
            var db = new GirlsTaxesEntities();
            DataTable table;
            //String query = "select * from ProductTaxes";
            //table = db.GetDataTable(query);

            List<GirlsTax> ptList = db.GirlsTaxes.Select(n=>n).ToList();

            var mysqlContext = new GirlAgencyMySql.Data.MySql();

            var girlsExpences = mysqlContext.Orders.Select(v => new
            {
                FirstName = v.Girl.FirstName,
                LastName = v.Girl.LastName,
                Income = v.Girl.PricePerHour * v.Duration

                //Expense = v.Expenses.Select(e => e.Money).FirstOrDefault(),
                //Income = mysqlContext.Products.Where(p => p.VendorId == v.Id).Select(p => p.Income).FirstOrDefault(),
                //Products = mysqlContext.Products.Where(p => p.VendorId == v.Id).Select(p => p.Id)
            }).ToList();

            List<string[]> dataList = new List<string[]>();

            for (int i = 0; i < girlsExpences.Count; i++)
            {
                decimal vendorTax = 0;
                foreach (var product in girlsExpences[i].FirstName)
                {
                    foreach (var productTax in ptList)
                    {
                        if (productTax.id == product)
                        {
                            vendorTax += Convert.ToDecimal(productTax.Tax) / 100 * girlsExpences[i].Income;
                        }
                    }
                }

                string[] dataObj =
                {
                    girlsExpences[i].FirstName.ToString(),
                    girlsExpences[i].Income.ToString(),
                    //(girlsExpences[i]. ?? 0).ToString(),
                    vendorTax.ToString(),
                    //(girlsExpences[i].Income - (girlsExpences[i].Expense ?? 0) - vendorTax).ToString()
                };

                dataList.Add(dataObj);
            }

            return dataList.ToArray();
        }