public IActionResult Add(AddExpenseViewModel addExpenseViewModel)
        {
            if (ModelState.IsValid)
            {
                ExpenseCategory newCategory =
                    context.ExpenseCategories.Single(c => c.ID == addExpenseViewModel.ExpenseCategoryID);
                // Add the new cheese to my existing cheeses
                Expense newExpense = new Expense
                {
                    Date      = addExpenseViewModel.Date,
                    Reference = addExpenseViewModel.Reference,
                    Owner     = addExpenseViewModel.Owner,

                    Description     = addExpenseViewModel.Description,
                    Amount          = addExpenseViewModel.Amount,
                    ExpenseCategory = newCategory
                };

                context.Expenses.Add(newExpense);
                context.SaveChanges();

                return(Redirect("/Expense"));
            }

            return(View(addExpenseViewModel));
        }
예제 #2
0
        public IActionResult Add(AddDriverLoadViewModel addDriverLoadViewModel)
        {
            if (ModelState.IsValid)
            {
                DriverName newDriver =
                    context.DriverNames.Single(c => c.ID == addDriverLoadViewModel.DriverNameID);
                // Add the new cheese to my existing cheeses
                Driver newTrip = new Driver
                {
                    Date        = addDriverLoadViewModel.Date,
                    Reference   = addDriverLoadViewModel.Reference,
                    Description = addDriverLoadViewModel.Description,
                    LoadMiles   = addDriverLoadViewModel.LoadMiles,
                    DeadMiles   = addDriverLoadViewModel.DeadMiles,

                    Rate       = addDriverLoadViewModel.Rate,
                    DriverName = newDriver
                };

                context.Drivers.Add(newTrip);
                context.SaveChanges();

                return(Redirect("/Driver"));
            }

            return(View(addDriverLoadViewModel));
        }
예제 #3
0
        public IActionResult Add(AddLoadViewModel addLoadViewModel)
        {
            if (ModelState.IsValid)
            {
                LoadCategory newLoadCategory =
                    context.LoadCategories.Single(c => c.ID == addLoadViewModel.LoadCategoryID);

                Load newLoad = new Load
                {
                    Date         = addLoadViewModel.Date,
                    Reference    = addLoadViewModel.Reference,
                    Description  = addLoadViewModel.Description,
                    Owner        = addLoadViewModel.Owner,
                    Amount       = addLoadViewModel.Amount,
                    LoadCategory = newLoadCategory,
                };



                context.Loads.Add(newLoad);
                context.SaveChanges();

                return(Redirect("/Load"));
            }

            return(View(addLoadViewModel));
        }
        public IActionResult Add(AddOwnerViewModel addOwnerViewModel)
        {
            if (ModelState.IsValid)
            {
                Owner newOwner = new Owner

                {
                    Name = addOwnerViewModel.Name
                };
                context.Owners.Add(newOwner);
                context.SaveChanges();
                return(Redirect("/Owner"));
            }
            return(View(addOwnerViewModel));
        }
        public IActionResult Add(AddLoadCategoryViewModel addLoadCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                LoadCategory newLoadCategory = new LoadCategory
                {
                    Name = addLoadCategoryViewModel.Name,
                };

                context.LoadCategories.Add(newLoadCategory);
                context.SaveChanges();

                return(Redirect("/LoadCategory"));
            }

            return(View(addLoadCategoryViewModel));
        }
예제 #6
0
        public IActionResult Add(AddDriverNameViewModel addDriverNameViewModel)
        {
            if (ModelState.IsValid)
            {
                DriverName newDriverName = new DriverName
                {
                    Name = addDriverNameViewModel.Name,
                };

                context.DriverNames.Add(newDriverName);
                context.SaveChanges();

                return(Redirect("/DriverName"));
            }

            return(View(addDriverNameViewModel));
        }