Esempio n. 1
0
        private TermModel GetNewTerm()
        {
            TermModel term = new TermModel();
            using (var db = new YNTCTermContext())
            {
                TermModel latestTerm = db.Term.OrderByDescending(e => e.Id).FirstOrDefault();

                term.PrevId = latestTerm.Id;
                //term.NextId = term.Id;
                db.SaveChanges();
                term.StartDate = latestTerm.StartDate.AddMonths(1);
                term.ProjectedGoal = latestTerm.ProjectedGoal;
                term.Categories = new List<CategoryModel>();

                foreach(CategoryModel catm in latestTerm.Categories)//perform deep copy
                {
                    CategoryModel new_catm = new CategoryModel { NameOfCategory = catm.NameOfCategory,
                    Customers = new List<CustomerModel>()
                    };

                    foreach(CustomerModel custm in catm.Customers)
                    {
                        CustomerModel new_custm = new CustomerModel
                        {
                            NameOfCompany = custm.NameOfCompany,
                            BudgetActualCustomer = new BudgetActualModel { Budget = 0, Actual = 0, Difference = 0 }
                        };
                        new_catm.Customers.Add(new_custm);
                    }
                    term.Categories.Add(new_catm);
                }
            }
            return term;
        }
Esempio n. 2
0
        public ActionResult TermDisplay(int? id)
        {
            TermModel term = new TermModel();
            if (id == null)
            {
                //determine which term is the current date
                //If the date does not exist, create it new and create any up until that point

            }
            else
            {
                //open term from database by id
                using (var db = new YNTCTermContext())
                {
                    term = db.Term.Find(id);
                    if(term==null)
                    {
                        term = GetNewTerm();
                        db.Term.Add(term);
                        db.SaveChanges();
                    }
                    term.BudgetActual = new BudgetActualModel
                    {
                        Budget = 0,
                        Actual = 0,
                        Difference = 0
                    };
                    foreach (CategoryModel termCategory in term.Categories)
                    {
                        termCategory.BudgetActualCategory = new BudgetActualModel
                        {
                            Budget = 0,
                            Actual = 0,
                            Difference = 0
                        };
                        foreach (CustomerModel termCustomer in termCategory.Customers)
                        {
                            termCustomer.BudgetActualCustomer.Difference = termCustomer.BudgetActualCustomer.Actual - termCustomer.BudgetActualCustomer.Budget;

                            termCategory.BudgetActualCategory.Budget += termCustomer.BudgetActualCustomer.Budget;
                            termCategory.BudgetActualCategory.Actual += termCustomer.BudgetActualCustomer.Actual;
                            termCategory.BudgetActualCategory.Difference += termCustomer.BudgetActualCustomer.Difference;

                        }
                        term.BudgetActual.Budget += termCategory.BudgetActualCategory.Budget;
                        term.BudgetActual.Actual += termCategory.BudgetActualCategory.Actual;
                        term.BudgetActual.Difference += termCategory.BudgetActualCategory.Difference;
                    }

                    //if term does not exist
                    //copy categories and budgeted from previous term from database

                   term.ProjectedGoal.ExpectedAmountToEarn = (term.ProjectedGoal.ExpectedAmountToEarn + term.ProjectedGoal.ExpectedAmountToEarn) / 2;
                }
            }
               return View("TermView", term);
        }