public async Task <IActionResult> Edit(Guid id, [Bind("ExpenseCategoryID,AccountsID,Amount,Date,Remarks,ID")] ExpenseHistory expenseHistory) { if (id != expenseHistory.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(expenseHistory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExpenseHistoryExists(expenseHistory.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AccountsID"] = new SelectList(_context.Accounts.OrderBy(x => x.AccountName), "ID", "AccountName", expenseHistory.AccountsID); ViewData["ExpenseCategoryID"] = new SelectList(_context.ExpenseCategory.OrderBy(x => x.Name), "ID", "Name", expenseHistory.ExpenseCategoryID); return(View(expenseHistory)); }
public async Task <ActionResult <ExpenseHistory> > PostExpenseHistory(ExpenseHistory expenseHistory) { _context.ExpenseHistory.Add(expenseHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetExpenseHistory", new { id = expenseHistory.Id }, expenseHistory)); }
public static void saveexpense(dynamic data) { ExpensesEntities db = new ExpensesEntities(); Expense newExpense = new Expense(); ExpenseHistory newExpenseHistory = new ExpenseHistory(); newExpense.UserId = data.expensedata.CurrentUserId; newExpense.CreatedDate = DateTime.Now; newExpense.TotalAmount = data.expensedata.TotalAmount; db.Expense.Add(newExpense); db.SaveChanges(); newExpenseHistory.ExpenseId = db.Expense.ToList().Last().Id; newExpenseHistory.ExpenseStatusId = 2; newExpenseHistory.Createdby_UserId = data.expensedata.CurrentUserId; db.ExpenseHistory.Add(newExpenseHistory); db.SaveChanges(); foreach (var item in data.expenseitemdata) { Data.ExpenseItem newExpenseItem = new Data.ExpenseItem(); newExpenseItem.ExpenseId = db.Expense.ToList().Last().Id; newExpenseItem.ExpenseType = item.ExpenseType; newExpenseItem.Description = item.Description; newExpenseItem.Amount = item.Amount; newExpenseItem.ExpenseDate = item.ExpenseDate; db.ExpenseItem.Add(newExpenseItem); } db.SaveChanges(); }
public async Task <IActionResult> PutExpenseHistory(int id, ExpenseHistory expenseHistory) { if (id != expenseHistory.Id) { return(BadRequest()); } _context.Entry(expenseHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExpenseHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("ExpenseCategoryID,AccountsID,Amount,Date,Remarks,ID")] ExpenseHistory expenseHistory) { if (ModelState.IsValid) { expenseHistory.ID = Guid.NewGuid(); _context.Add(expenseHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AccountsID"] = new SelectList(_context.Accounts.OrderBy(x => x.AccountName), "ID", "AccountName", expenseHistory.AccountsID); ViewData["ExpenseCategoryID"] = new SelectList(_context.ExpenseCategory.OrderBy(x => x.Name), "ID", "Name", expenseHistory.ExpenseCategoryID); return(View(expenseHistory)); }
private void DoWork() { while (true) { //// var expenseList = db.Expense.Where(q => q.StatusId == 1).Where(q => q.IsNotificationSent == false).Include(e => e.AspNetUsers).Include(e => e.ExpenseStatus); foreach (Expense expense in expenseList) { using (var myDB = new ExpenseEntities()) { var correspondingExpenseHistory = myDB.ExpenseHistory.Where(q => q.ExpenseId == expense.Id).Where(q => q.StatusId == myDB.ExpenseStatus.FirstOrDefault(o => o.Description == "Manager Approval Pending").Id); List <ExpenseHistory> sortedHistoryList = correspondingExpenseHistory.OrderBy(o => o.ModifyDate).ToList(); ExpenseHistory expenseHistory = sortedHistoryList.FirstOrDefault(); DateTime sendDate = expenseHistory.ModifyDate; //if ((DateTime.Now - sendDate).TotalHours > 48) if ((DateTime.Now - sendDate).TotalSeconds > 10) { Console.WriteLine("************"); Console.WriteLine(expense.Description + " needs a notification."); Console.WriteLine("************"); SendEmail(expense); try { myDB.Expense.Find(expense.Id).IsNotificationSent = true; myDB.Expense.Find(expense.Id).NotificationDate = DateTime.Now; myDB.SaveChanges(); } catch (Exception e) { Console.WriteLine("There is a problem"); } } } Console.WriteLine("checking..."); if (_semaphoreToRequestStop.Wait(500 * 10 / 2)) { Console.WriteLine("Stopped"); break; } } } }
public static void CreateExpenseHistory(int expenseId, ExpenseAppEntities entity, string rejectReason) { var expense = (from e in entity.Expenses where e.ID == expenseId select e).First(); ExpenseHistory expenseHistory = new ExpenseHistory(); expenseHistory.ExpenseId = expense.ID; expenseHistory.CreatedBy = expense.UserId; expenseHistory.CreatedDate = DateTime.Now; switch (expense.LastExpenseActionId) { case 1: expenseHistory.ExpenseStatusId = (int)StatusEnum.Ongoing; break; case 2: expenseHistory.ExpenseStatusId = (int)StatusEnum.WaitingForManagerApproval; break; case 3: expenseHistory.ExpenseStatusId = (int)StatusEnum.WaitingForAccountantApproval; break; case 4: expenseHistory.ExpenseStatusId = (int)StatusEnum.Completed; break; case 5: expenseHistory.ExpenseStatusId = (int)StatusEnum.Rejected; expenseHistory.RejectReason = rejectReason; break; } entity.SaveChanges(); entity.ExpenseHistories.Add(expenseHistory); entity.SaveChanges(); }
public void ExpenseHistoryDelete(ExpenseHistory expenseHistory) { ExpenseHistoryRepository.Delete(expenseHistory); }
public void ExpenseHistorySaveOrUpdate(ExpenseHistory expenseHistory) { ExpenseHistoryRepository.SaveOrUpdate(expenseHistory); }