Exemplo n.º 1
0
        public ActionResult DeleteCategory(int? id, int? termID)
        {
            var deleteCategoryContext = new YNTCTermContext();
            TempData["termId"] = termID;

            CategoryModel cm = deleteCategoryContext.CategoryModels.Find(id);
            return View("DeleteCategoryView", cm);
        }
Exemplo n.º 2
0
        public ActionResult CreateNewCategory(int? id)
        {
            var createCategoryContext = new YNTCTermContext();

            TempData["termId"] = id;
            CategoryModel cm = createCategoryContext.CategoryModels.Find(id);
            return View("CreateNewCategoryView", cm);
        }
Exemplo n.º 3
0
        public ActionResult CreateNewCustomer(int? id, int? termID)
        {
            var createCustomerContext = new YNTCTermContext();

            TempData["categoryModel"] = id;
            TempData["TermId"] = termID;

            CustomerModel cm = createCustomerContext.CustomerModels.Find(id);
            return View("CreateNewCustomerView", cm);
        }
Exemplo n.º 4
0
        public ActionResult CreateNewCategory(CategoryModel categoryModel)
        {
            var createCategoryContext = new YNTCTermContext();
            int? termId = (int?)TempData["termId"];

            var currentTerm = createCategoryContext.Term.Find(termId);
            currentTerm.Categories.Add(categoryModel);

            if (ModelState.IsValid)
            {
                createCategoryContext.Entry(categoryModel).State = EntityState.Added;
                createCategoryContext.SaveChanges();
                return RedirectToAction("MonthOverview", currentTerm);
            }
            return View("CreateNewCategoryView", categoryModel);
        }
Exemplo n.º 5
0
        public ActionResult CreateNewCustomer(CustomerModel customerModel)
        {
            var createCustomerContext = new YNTCTermContext();
            int? categoryModel = (int?)TempData["categoryModel"];
            int? termId = (int?)TempData["termId"];

            var currentTerm = createCustomerContext.Term.Find(termId);

            CategoryModel modelOfCategory = createCustomerContext.CategoryModels.Find(categoryModel);
            modelOfCategory.Customers.Add(customerModel);

            if (ModelState.IsValid)
            {
                createCustomerContext.Entry(customerModel).State = EntityState.Added;
                createCustomerContext.SaveChanges();
                return RedirectToAction("MonthOverview", currentTerm);
            }
            return View("CreateNewCustomerView");
        }
Exemplo n.º 6
0
        public ActionResult DeleteCategory([Bind(Include = "Id, NameOfCategory")] CategoryModel categoryModel)
        {
            var deleteCategoryContext = new YNTCTermContext();
            int? termId = (int?)TempData["termId"];

            var currentTerm = deleteCategoryContext.Term.Find(termId);

            if (ModelState.IsValid)
            {
                deleteCategoryContext.Entry(categoryModel).State = EntityState.Deleted;
                deleteCategoryContext.CategoryModels.Remove(categoryModel);
                deleteCategoryContext.SaveChanges();
                return RedirectToAction("MonthOverview", currentTerm);
            }
            return View("DeleteCategoryView");
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public ActionResult SaleClosed([Bind(Include = "Id, NameOfCompany, BudgetActualCustomer")] CustomerModel customerModel)
        {
            var saleClosedCustomerContext = new YNTCTermContext();
            int? termId = (int?)TempData["termId"];

            var currentTerm = saleClosedCustomerContext.Term.Find(termId);

            if (ModelState.IsValid)
            {
                saleClosedCustomerContext.Entry(customerModel).State = EntityState.Modified;
                saleClosedCustomerContext.SaveChanges();
                return RedirectToAction("MonthOverview", currentTerm);
            }
            return View("SaleClosedView");
        }
Exemplo n.º 10
0
        public ActionResult SaleClosed(int? id, int? termID)
        {
            var saleClosedCustomerContext = new YNTCTermContext();
            TempData["termId"] = termID;

            CustomerModel cm = saleClosedCustomerContext.CustomerModels.Find(id);
            return View("SaleClosedView", cm);
        }
Exemplo n.º 11
0
        public ActionResult ProjectedGoal([Bind(Include = "Id, ExpectedAmountToEarn")] ProjectedGoalModel projectedGoalModel)
        {
            var projectedGoalContext = new YNTCTermContext();
            int? termId = (int?)TempData["termId"];
            YNTCTermContext db = new YNTCTermContext();
            TermModel term = projectedGoalContext.Term.Find(termId);

            if (term == null)
            {
                term = GetNewTerm();
                db.Term.Add(term);
                db.SaveChanges();
            }
            term.ProjectedGoal = projectedGoalModel;

            if (ModelState.IsValid)
            {
                projectedGoalContext.Entry(projectedGoalModel).State = EntityState.Added;
                projectedGoalContext.SaveChanges();
                return RedirectToAction("MonthOverview");
            }
            return View("ProjectedGoalView");
        }
Exemplo n.º 12
0
        public ActionResult EditCustomer(int? id, int? termID)
        {
            var editCustomerContext = new YNTCTermContext();
            TempData["termId"] = termID;

            CustomerModel cm = editCustomerContext.CustomerModels.Find(id);
            return View("EditCustomerView", cm);
        }
Exemplo n.º 13
0
        public ActionResult EditCategory(int? id, int? termID)
        {
            var editCategoryContext = new YNTCTermContext();
            TempData["termId"] = termID;

            CategoryModel cateModel = editCategoryContext.CategoryModels.Find(id);
            return View("EditCategoryView", cateModel);
        }
Exemplo n.º 14
0
        public ActionResult DetailsCustomer([Bind(Include = "Id, ContactName, CustomerMotivations")]CustomerModel customerModel, DetailsCustomerModel detailsModel)
        {
            var createDetailsContext = new YNTCTermContext();
            int? termId = (int?)TempData["termId"];

            //var currentTerm = createDetailsContext.Term.Find(termId);

            var detailsOnCustomerId = createDetailsContext.CustomerModels.Find(customerModel.Id);
            detailsOnCustomerId.DetailsOfCustomer = detailsModel;

            if (ModelState.IsValid)
            {
                createDetailsContext.Entry(detailsModel).State = EntityState.Added;
                createDetailsContext.SaveChanges();
                RedirectToAction("MonthOverview", detailsModel);
            }
            return View("DetailsCustomerView", detailsModel);
        }
Exemplo n.º 15
0
        public ActionResult DetailsCustomer(int? id, int? termID)
        {
            var createDetailsContext = new YNTCTermContext();
            TempData["termId"] = termID;

            DetailsCustomerModel dm = createDetailsContext.CustomerModels.Find(id).DetailsOfCustomer;
            return View("DetailsCustomerView", dm);
        }