Пример #1
0
 public ActionResult Add(Expense model, int id, string dat1, string dat2)
 {
     if (id != null && id != 0)
     {
         try
         {
             if (ModelState.IsValid)
             {
                 model.Date_Time = DateTime.Now;
                 model.Userid    = id;
                 db.Expenses.Add(model);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             //Log the error (uncomment dex variable name and add a line here to write a log.
             ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
         }
     }
     else
     {
         ModelState.AddModelError("", "Unable to save changes. You did not choose User");
     }
     return(RedirectToAction("ManageExpenses", new { UserId = id, dat11 = dat1, dat22 = dat2 }));
 }
Пример #2
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddExpenseTypeWindow addWindow = new AddExpenseTypeWindow();
                var result = addWindow.ShowDialog();

                if (result == false)
                {
                    return;
                }

                ExpenseType newExpenseType = addWindow.ExpenseType;

                _expenseTypes.Add(newExpenseType);
                _expenseContext.ExpenseTypes.Add(newExpenseType);
                _expenseContext.SaveChanges();

                expenseTypesDataGrid.Items.Refresh();
            }
            catch (Exception exeption)
            {
                MessageBox.Show(exeption.Message);
            }
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "Id,Sum,Comment,OperationTime,WalletID,ExpenseCategoryID")] ExpenseModel expenseModel)
        {
            if (ModelState.IsValid)
            {
                db.ExpenseModels.Add(expenseModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(expenseModel));
        }
Пример #4
0
 public ActionResult Create(Expense expense)
 {
     if (expense.AttchFile != null)
     {
         using (var memoryStream = new MemoryStream())
         {
             expense.AttchFile.CopyTo(memoryStream);
             expense.Attachment = memoryStream.ToArray();
             expense.FileName   = expense.AttchFile.FileName;
         }
     }
     _context.Add(expense);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #5
0
        public ExpenseController(ExpenseContext context)
        {
            _context = context;

            if (_context.ExpenseItems.Count() == 0)
            {
                _context.SaveChanges();
            }
        }
 public Expense CreateExpense(Expense expense)
 {
     _expenseContext.Add(expense);
     if (_expenseContext.SaveChanges() > 0)
     {
         return(expense);
     }
     return(null);
 }
 public void AddExpenseReport(ExpenseReport report)
 {
     using (ExpenseContext db = new ExpenseContext())
     {
         db.Database.Connection.ConnectionString = "Data Source=mainstorage.database.windows.net;Initial Catalog=ExpenseReportingDatabase;Integrated Security=False;User ID=HECFLORES1993;Password=Armandorocha1-;Connect Timeout=15;Encrypt=True;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
         db.ExpenseReports.Add(report);
         db.SaveChanges();
     }
 }
Пример #8
0
        /// <summary>
        /// Handle the command.
        /// </summary>
        /// <param name="command"></param>
        public void Handle(DeleteExpenseLineInfo command)
        {
            ExpenseLine expenseLineToDelete = expenseDb.ExpenseLines
                                              .Where(e => e.expenseLineId == command.expenseLineId)
                                              .SingleOrDefault();

            expenseDb.ExpenseLines.Remove(expenseLineToDelete);

            expenseDb.SaveChanges();
        }
        public ActionResult Edit(Expense expense)
        {
            var id = expense.Expense_id;
            var expenseToUpdate = db.Expenses.Find(id);

            if (TryUpdateModel(expenseToUpdate, "", new string[] { "Name", "Amount", "Comment" }))
            {
                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return(View(expense));
        }
Пример #10
0
        public UpdateExpenseValidatorTests()
        {
            expenseDb = DatabaseSetup.CreateExpenseContext();
            updateExpenseValidator = new UpdateExpenseValidator(expenseDb);

            expenseDb.Expenses.Add(new Expense()
            {
                expenseId = 1
            });

            expenseDb.SaveChanges();
        }
Пример #11
0
        public AddUpdateExpenseValidatorTests()
        {
            expenseDb = DatabaseSetup.CreateExpenseContext();
            addUpdateExpenseValidator = new AddUpdateExpenseValidator(expenseDb);

            // Add an existing expense/expense line
            expenseDb.Expenses.Add(new Expense()
            {
                expenseId = 1
            });

            expenseDb.SaveChanges();
        }
Пример #12
0
        public IActionResult Create(ExpenseCreateViewModel NewExpense)
        {
            List <ExpenseProduct> products = new List <ExpenseProduct>();

            foreach (var productId in NewExpense.SelectedProductId)
            {
                products.Add(new ExpenseProduct()
                {
                    ProductId = productId
                });
            }
            _expenseDatabase.Expenses.Add(new Expense
            {
                Amount          = NewExpense.Amount,
                Date            = NewExpense.Date,
                Description     = NewExpense.Description,
                Category        = NewExpense.Category,
                PaymentStatusId = NewExpense.PaymentStatusId,
                ExpenseProducts = products,
                UserId          = User.FindFirstValue(ClaimTypes.NameIdentifier)
            });
            _expenseDatabase.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #13
0
        /// <summary>
        /// This handles the command making all the required changes
        /// to the database.
        /// </summary>
        /// <param name="command"></param>
        public void Handle(AddUpdateExpenseLineInfo command)
        {
            ExpenseLine existingLine = expenseDb.ExpenseLines.Where(e => e.expenseLineId == command.expenseLineId)
                                       .SingleOrDefault();

            if (existingLine == null)
            {
                expenseDb.ExpenseLines.Add(command.GetExpenseLine());
            }
            else
            {
                expenseDb.Entry(existingLine).CurrentValues.SetValues(command);
            }

            expenseDb.SaveChanges();
        }
Пример #14
0
        public XmlExtractorController(ExpenseContext expenseContext, ReservationContext reservationContext)
        {
            ReservationContext = reservationContext;

            if (reservationContext.ReservationItems.Count() == 0)
            {
                reservationContext.SaveChanges();
            }

            ExpenseContext = expenseContext;

            if (expenseContext.ExpenseItems.Count() == 0)
            {
                expenseContext.SaveChanges();
            }
        }
Пример #15
0
        public AddUpdateExpenseLineValidatorTests()
        {
            expenseDb = DatabaseSetup.CreateExpenseContext();
            addUpdateExpenseLineValidator = new AddUpdateExpenseLineValidator(expenseDb);

            expenseDb.Expenses.Add(new Expense()
            {
                expenseId = 1
            });
            expenseDb.ExpenseLines.Add(new ExpenseLine()
            {
                expenseLineId = 1,
                expenseId     = 1
            });

            expenseDb.SaveChanges();
        }
Пример #16
0
        public ActionResult AddExpense(Expense Expense)    //DO NOT change the action name
        {
            var viewModel = new ExpenseViewModel();

            ViewBag.ExpenseTypes = viewModel.ExpenseTypeList;
            //fill code here
            if (ModelState.IsValid)
            {
                var context = new ExpenseContext();
                context.Expenses.Add(Expense);
                context.SaveChanges();

                //   return RedirectToAction("Index");
                return(View(viewModel));
            }
            ViewBag.Flag = 1;
            return(View(viewModel));
        }
Пример #17
0
        /// <summary>
        /// This handles the command making all hte required changes
        /// to the database.
        /// If the expense lines are being updated then call the
        /// appropriate commands for them.
        /// </summary>
        /// <param name="command"></param>
        public void Handle(AddUpdateExpenseInfo command)
        {
            Expense existing = expenseDb.Expenses
                               .Where(e => e.expenseId == command.expenseId)
                               .Include(e => e.expenseLines)
                               .SingleOrDefault();

            if (existing == null)
            {
                expenseDb.Expenses.Add(command.GetExpense());
            }
            else
            {
                expenseDb.Entry(existing).CurrentValues.SetValues(command);

                // Only update the expense lines if they are specified
                if (command.UpdateExpenseLines())
                {
                    List <int> linesToDelete = new List <int>();

                    // Check expense lines and delete any that no longer exist
                    foreach (ExpenseLine existingLine in existing.expenseLines)
                    {
                        if (!command.expenseLines.Any(el => el.expenseLineId == existingLine.expenseLineId))
                        {
                            linesToDelete.Add(existingLine.expenseLineId);
                        }
                    }
                    foreach (int expenseLineId in linesToDelete)
                    {
                        deleteExpenseLine.Handle(new DeleteExpenseLineInfo(expenseLineId));
                    }

                    // Update and add any expense lines
                    foreach (ExpenseLine lineToProcess in command.expenseLines)
                    {
                        addUpdateExpenseLine.Handle(new AddUpdateExpenseLineInfo(lineToProcess));
                    }
                }
            }

            expenseDb.SaveChanges();
        }
Пример #18
0
 public ExpenseController(IConfiguration configuration, ExpenseContext context)
 {
     _configuration = configuration;
     _context       = context;
     if (_context.Expenses.Count() == 0)
     {
         // Create some new Expenses if collection is empty,
         _context.Expenses.Add(new Expense {
             ExpenseDate = DateTime.UtcNow,
             Amount      = 43.5M,
             Reason      = "Rail ticket to T.A."
         });
         _context.Expenses.Add(new Expense {
             ExpenseDate = DateTime.UtcNow,
             Amount      = 51.5M,
             Reason      = "Rail ticket to BeerSheva"
         });
         _context.SaveChanges();
     }
 }
Пример #19
0
        public async void GetExpenses_ReturnsTwoItems_WhenDBIsNotEmpty()
        {
            //Arrange
            //DBContext
            var optionsBuilder = new DbContextOptionsBuilder <ExpenseContext>();

            optionsBuilder.UseInMemoryDatabase("UnitTestInMemBD2");
            var dbContext = new ExpenseContext(optionsBuilder.Options);

            dbContext.Add(new Expense()
            {
                Amount      = 88.49f,
                Currency    = Currency.EUR,
                Description = "Skateboard trucks"
            });

            dbContext.Add(new Expense()
            {
                Amount      = 49.99f,
                Currency    = Currency.EUR,
                Description = "Skateboard deck"
            });

            dbContext.SaveChanges();

            var expenseRepo = new ExpenseRepository(dbContext);

            //Controller
            var controller = new ExpensesController(expenseRepo);

            //Act
            var result = await controller.GetExpenses();

            //Assert
            Assert.Equal(2, result.Value.Count);
        }
Пример #20
0
 public void Post([FromBody] Expense expense)
 {
     _context.Add(expense);
     _context.SaveChanges();
 }
Пример #21
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Пример #22
0
 public ActionResult AddExpense(EMS_DB expense)
 {
     con.EMS_DB.Add(expense);
     con.SaveChanges();
     return(View("AddExpense"));
 }