コード例 #1
0
        public async Task <IActionResult> PutExpenseItem(long id, ExpenseItem expenseItem)
        {
            if (id != expenseItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(expenseItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExpenseItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutExpense([FromRoute] string id, [FromQuery] bool approved)
        {
            var _expense = await _context.Expenses.AsNoTracking().Include("Employee").SingleOrDefaultAsync(_exp => _exp.UUID == id);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_expense == null)
            {
                return(NotFound($"Expense not found with the UUID {id}"));
            }

            var newExpense = new Expense()
            {
                Description = _expense.Description,
                Amount      = _expense.Amount,
                Created_at  = _expense.Created_at,
                Approved    = approved,
                Currency    = _expense.Currency,
                Employee    = _expense.Employee,
                UUID        = id
            };

            try
            {
                _context.Entry(newExpense).Property(x => x.Approved).IsModified = true; //just update approved field
                await _context.SaveChangesAsync();
            }
            catch (Exception error)
            {
                return(BadRequest(error.Message));
            }


            await _context.Entry(newExpense).Reference(x => x.Employee).LoadAsync();

            var expenseDto = new ExpenseDTO()
            {
                ExpenseUUID  = newExpense.UUID,
                EmployeeUUID = newExpense.Employee.UUID,
                First_Name   = newExpense.Employee.First_name,
                Amount       = newExpense.Amount,
                Approved     = newExpense.Approved
            };

            return(CreatedAtAction("GetExpense", new { id = newExpense.UUID }, expenseDto));
        }
コード例 #3
0
        public async Task <IActionResult> PutBudget(int id, Budget budget)
        {
            if (id != budget.Id)
            {
                return(BadRequest());
            }

            _context.Entry(budget).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BudgetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            var selectedRow = _expenseTypes[_selectedIndex];

            EditWindow editWindow = new EditWindow(selectedRow);
            var        result     = editWindow.ShowDialog();

            if (result == false)
            {
                return;
            }

            //editing local list
            selectedRow = editWindow.Model;

            //editing database
            var oldRecord = _expenseContext.ExpenseTypes
                            .Where(x => x.Id == selectedRow.Id)
                            .FirstOrDefault();

            _expenseContext.Entry(oldRecord).CurrentValues.SetValues(selectedRow);
            _expenseContext.SaveChanges();

            expenseTypesDataGrid.Items.Refresh();
        }
コード例 #5
0
        public async Task <IActionResult> PutRecepit(long id, Recepit recepit)
        {
            if (id != recepit.Id)
            {
                return(BadRequest());
            }

            _context.Entry(recepit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecepitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "Id,Sum,Comment,OperationTime,WalletID,ExpenseCategoryID")] ExpenseModel expenseModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(expenseModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(expenseModel));
 }
コード例 #7
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();
        }
コード例 #8
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();
        }
コード例 #9
0
 public async Task UpdateAsync(Expense expense)
 {
     _dbContext.Entry(expense).State = EntityState.Modified;
     await _dbContext.SaveChangesAsync();
 }