public async Task <IActionResult> Post([FromBody] Models.Expense expense) { //TODO: Check problems with date... if (expense == null) { //_logger.LogInformation($"User is empty when accessing to UserController/Post(UserDto expense)."); return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isCreated = await _expenseService.AddExpense(expense); if (isCreated) { return(Created("", null)); } else { // _logger.LogError($"Add User is not valid. Error in SaveAsync(). When accessing to UserController/Post"); return(StatusCode(500, "A problem happend while handling your request.")); } }
public async Task <IActionResult> Edit(int id, [FromBody] Models.Expense expenseRequest) { try { if (expenseRequest == null) { return(BadRequest("Object cannot be null")); } // Update entity in repository var isUpdated = await _expenseService.EditExpense(expenseRequest, id); if (isUpdated) { return(NoContent()); } else { _logger.LogError($"Edit expense a problem happend. Error in updateExpense. When accessing to ExpenseController/Edit"); return(StatusCode(500, "A problem happend while handling your request.")); } } catch (Exception ex) { // Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PutStockItemAsync), ex); } return(NoContent()); }
public async Task <bool> EditExpense(Models.Expense expenseRequest, int id) { // Get stock item by id var expenseFromDB = await _expenseRepository.GetAsync(id); // Validate if entity exists if (expenseFromDB == null) { return(false); } // Set changes to entity var dto = _mapper.Map <Models.Expense, Entities.Expense>(expenseRequest, expenseFromDB); try { _expenseRepository.Update(dto); } catch (Exception ex) { _logger.LogError($"Edit Expense catch exception when update row. {ex}"); return(false); } if (!await _expenseRepository.SaveAsync()) { _logger.LogError($"Edit Expense is not valid. Error in SaveAsync(). When accessing to ExpenseService/Edit"); return(false); } return(true); }
public ActionResult DeleteExpense(int a) { Expense e = new Models.Expense(); e.E_ID = a; e.delete(); return(RedirectToAction("Expense")); }
public ActionResult UpdateExpense(int a) { Expense e = new Models.Expense(); Exp_Cat ec = new Models.Exp_Cat(); ViewBag.Expcat = ec.all(); e.E_ID = a; e.search(); return(View(e)); }
public ActionResult Save(FormCollection form) { List <string> names, dates, descriptions, costs; //Get values names = new List <string>(form.GetValues("name[]")); dates = new List <string>(form.GetValues("date[]")); descriptions = new List <string>(form.GetValues("description[]")); costs = new List <string>(form.GetValues("cost[]")); string formName = string.Empty; //Create new form if (!string.IsNullOrEmpty(form["formName"])) { formName = form["formName"]; } // TODO: validation double totalCost = costs.Sum(c => double.Parse(c)); Models.Form newForm = new Models.Form(); newForm = FormHelper.Create(formName, totalCost); using (ExpenseEntities db = new ExpenseEntities()) { Models.Expense expense; for (int i = 0; i < names.Count; i++) { expense = new Models.Expense(); expense.Id = Guid.NewGuid(); expense.Name = names[i]; expense.Date = DateTime.Parse(dates[i]); expense.Description = descriptions[i]; expense.Cost = int.Parse(costs[i]); expense.FormId = newForm.Id; expense.StateId = newForm.StateId; db.Expenses.Add(expense); } db.SaveChanges(); } return(RedirectToAction("New", "Expense")); }
public async Task <bool> AddExpense(Models.Expense expense) { var expenseEntity = _mapper.Map <Entities.Expense>(expense); // await _expenseRepository.AddAsync(expenseEntity); if (!await _expenseRepository.SaveAsync()) { // _logger.LogError($"Add User is not valid. Error in SaveAsync(). When accessing to UserController/Post"); return(false); } return(true); }
public async Task PostExpenses_ShouldReturnBadRequestObjectIsNull() { // Arrange var expenseObj = new Models.Expense(); expenseObj = null; var controller = new ExpenseController(null, null); // Act var badRequestResult = await controller.Post(expenseObj) as BadRequestResult; // Assert Assert.AreEqual(400, badRequestResult.StatusCode, "Badrequest does not works. Method post"); }
public ActionResult Reject(Guid id) { Models.Expense expense = new Models.Expense(); ExpenseEntities db = new ExpenseEntities(); expense = db.Expenses.Where(e => e.Id == id).FirstOrDefault(); State state = db.States.Where(s => s.Name == "Reject").FirstOrDefault(); expense.StateId = state.Id; Guid formId = expense.FormId; db.SaveChanges(); return(RedirectToAction("List", "Expense", new { id = formId })); }
public async Task Setup() { await InitDatabaseInMemoryTest(); expenseModelLists = new List <Models.Expense>(); expenseEntityLists = new List <Entities.Expense>(); mockRepo = new Mock <IExpenseRepository>(); mockMapper = new Mock <IMapper>(); mockLogger = new Mock <ILogger>(); expenseEntityObj = new Entities.Expense { Id = 2, Comment = "Expense1" }; expenseModelObj = new Models.Expense { Id = 2, Comment = "Expense2" }; expenseModelLists.Add(expenseModelObj); }
public void Update(int id, Models.Expense item) { var expense = Context.Expenses.FirstOrDefault(x => x.Id.Equals(id)); if (expense == null) { throw new InvalidOperationException(); } expense.Amount = item.Amount; expense.Categories = item.Categories; expense.Date = item.Date; expense.MethodOfPayment = item.MethodOfPayment; expense.Name = item.Name; expense.Recurrent = item.Recurrent; Context.SaveChanges(); }
public void Setup() { expenseObj = new Entities.Expense { Id = 2, Comment = "Expense2" }; expenseModelObj = new Models.Expense { Id = 2, Comment = "Expense2" }; mockExpenseRepository = new Mock <IExpenseRepository>(); mockExpenseService = new Mock <IExpenseService>(); mockLogger = new Mock <ILogger>(); expectedIdOfExpense = 2; expenseListObj = new List <Models.Expense>() { new Models.Expense { Id = 2, Comment = "Expense2" } }; }
public ActionResult Expense() { Expense ex = new Models.Expense(); Exp_Cat ec = new Models.Exp_Cat(); ViewBag.ec = ec.all(); if (TempData["type"] != null) { if (TempData["type"] == "ecid") { ex.EC_Name = TempData["value"].ToString(); ec.searchbyname(); return(View(ex.expensebyecid())); } else { ex.Name = (string)TempData["value"]; return(View(ex.expbyname())); } } return(View(ex.all())); }
private void LoadVendorExpensesToSqlServer(IList <string[]> expenses) { using (var supermarketContext = new SupermarketContext()) { foreach (var expense in expenses) { string vendorName = expense[0]; int vendorID = supermarketContext.Vendors.First(v => v.VendorName == vendorName).ID; decimal value = decimal.Parse(expense[2]); Models.Expense newExpense = new Models.Expense() { VendorID = vendorID, Month = DateTime.Parse(expense[1]), Value = value }; supermarketContext.Expenses.Add(newExpense); } supermarketContext.SaveChanges(); } }
private void LoadVendorExpensesToSqlServer(IList<string[]> expenses) { using (var supermarketContext = new SupermarketContext()) { foreach (var expense in expenses) { string vendorName = expense[0]; int vendorID = supermarketContext.Vendors.First(v => v.VendorName == vendorName).ID; decimal value = decimal.Parse(expense[2]); Models.Expense newExpense = new Models.Expense() { VendorID = vendorID, Month = DateTime.Parse(expense[1]), Value = value }; supermarketContext.Expenses.Add(newExpense); } supermarketContext.SaveChanges(); } }
// WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON private void buttonSave_Click(object sender, EventArgs e) { try { // Create the new Model, case don't exists if (item == null) { item = new Models.Expense(); } item.Description = tbDescription.Text; item.Price = Double.Parse(tbPrice.Text); item.Count = Double.Parse(tbCount.Text); item.Date = dpDate.Value.Date; // Case if a new item if (item.Id == -1) { db.Insert(item); } // Case is a existent item else { db.Update(item); } // Close the edit form this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Confira os dados inseridos", MessageBoxButtons.OK, MessageBoxIcon.Error); // Destroy the temp item if (item.Id == -1) { item = null; } } finally { } }
private void Add_Appointment(object sender, RoutedEventArgs e) { if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12) { BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12) { EndHour = (Convert.ToInt32(EndHour) + 12).ToString(); } if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12) { BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString(); } if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12) { EndHour = (Convert.ToInt32(EndHour) - 12).ToString(); } try { DateTime expenseDueDate = Convert.ToDateTime(ExpenseDueDate.ToString()); DateTime help = Convert.ToDateTime(DateRecieved.ToString()); DateTime startDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0); DateTime endDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0); string[] separators = new string[] { ", " }; string staff = Staff.SelectedValue.ToString(); string grant = Grant.SelectedValue.ToString(); Models.FCS_DBModel db = new Models.FCS_DBModel(); //MessageBox.Show(PatientBill + "\n" + DonorBill + "\n" + startDateTime + "\n" + endDateTime + "\n" + expenseDueDate + "\n" + staff, grant); string[] words = staff.Split(separators, StringSplitOptions.None); string FName = words[0]; string LName = words[1]; string username = words[2]; var staffID = (from dc in db.Staff where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username select dc.StaffID).Distinct().FirstOrDefault(); var grantproposalID = (from g in db.GrantProposals where g.GrantName == grant select g.GrantProposalID).Distinct().FirstOrDefault(); var donationID = (from d in db.Donations where d.GrantProposalID == grantproposalID select d.DonationID).Distinct().FirstOrDefault(); var donation = (from d in db.Donations where d.GrantProposalID == grantproposalID select d).First(); if (donation.DonationAmountRemaining >= DonorBill) { Models.Appointment a = new Models.Appointment(); a.StaffID = staffID; a.AppointmentStartDate = startDateTime; a.AppointmentEndDate = endDateTime; db.Appointments.Add(a); db.SaveChanges(); Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = 1; expense.DonationID = donationID; expense.PatientID = PatientID; expense.AppointmentID = a.AppointmentID; expense.ExpenseDueDate = expenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (ExpensePaidDate.IsEnabled == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); donation.DonationAmountRemaining = donation.DonationAmountRemaining - DonorBill; db.SaveChanges(); this.Close(); } else { MessageBox.Show("This would result in a negative balance."); } } catch (Exception ex) { MessageBox.Show("Please check the data entered."); } }
// ###################################################### #endregion #region IExpenseRepository member // ###################################################### public void InsertExpense(Models.Expense Entity) { this._context.Expenses.Add(Entity); }
public void UpdateExpense(Models.Expense Entity) { this._context.Entry(Entity).State = System.Data.Entity.EntityState.Modified; }
public void Create(Models.Expense item) { item = Context.Expenses.Add(item); Context.SaveChanges(); }
private void Add_Expense(object sender, RoutedEventArgs e) { Models.FCS_DBModel db = new Models.FCS_DBModel(); try { //Taking the money from a grant if (DonorDeduction.IsChecked.Value) { string grant = Grant.SelectedValue.ToString(); var grantproposalID = (from g in db.GrantProposals where g.GrantName == grant select g.GrantProposalID).Distinct().FirstOrDefault(); var grantDonation = (from d in db.Donations where d.GrantProposalID == grantproposalID select d).First(); if (grantDonation.DonationAmountRemaining >= DonorBill) { Models.Expense expense = new Models.Expense(); var donationID = (from d in db.Donations where d.GrantProposalID == grantproposalID select d.DonationID).Distinct().FirstOrDefault(); expense.DonationID = donationID; expense.ExpenseTypeID = ExpenseTypeID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); grantDonation.DonationAmountRemaining = grantDonation.DonationAmountRemaining - DonorBill; db.SaveChanges(); this.Close(); } else { MessageBox.Show("That grant does not have enough money."); } } //taking the money from a money donation. else { string[] separators = new string[] { ", " }; string Don = MoneyDonation.SelectedValue.ToString(); //MessageBox.Show(ItemName + "\n" + ItemDescription + "\n" + DateRecieved + "\n" + Indiv); string[] words = Don.Split(separators, StringSplitOptions.None); int donationID = Convert.ToInt32(words[0]); var donation = (from d in db.Donations where d.DonationID == donationID select d).First(); if (donation.DonationAmountRemaining >= DonorBill) { Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = ExpenseTypeID; expense.DonationID = donationID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); var donor = (from d in db.Donors where d.DonorID == donation.DonorID select d).First(); if (donor.DonorType != "Insurance") { donation.DonationAmountRemaining = donation.DonationAmountRemaining - DonorBill; } db.SaveChanges(); this.Close(); } else { MessageBox.Show("That donation does not have enough money."); } } } catch { //MessageBox.Show(DonorBill.ToString()); if (DonorBill == 0) { try { Models.Expense expense = new Models.Expense(); expense.ExpenseTypeID = ExpenseTypeID; expense.PatientID = Individual.PatientID; expense.AppointmentID = AppointmentID; expense.ExpenseDueDate = ExpenseDueDate; expense.DonorBill = DonorBill; expense.PatientBill = PatientBill; expense.TotalExpenseAmount = DonorBill + PatientBill; if (IsPaid.IsChecked.Value == true) { expense.ExpensePaidDate = Convert.ToDateTime(ExpensePaidDate.ToString()); } db.Expenses.Add(expense); db.SaveChanges(); this.Close(); } catch (Exception exc) { MessageBox.Show("Please make sure all fields are correct: " + exc); } } else { MessageBox.Show("Make sure to select a grant"); } } }
public EditExpenseForm(Models.Expense item) : this() { this.item = item; }