public ExpenseModel GetExpenseDetail([FromBody] Expense expense) { var expenseDetail = db.Expense.FirstOrDefault(x => x.ExpenseId == expense.ExpenseId); ExpenseModel expenseModel = new ExpenseModel() { Category2 = expenseDetail.Category2, Category1Id = db.Category2.FirstOrDefault(x => x.Category2Id == expenseDetail.Category2).Category1Id, Description = expenseDetail.Description, Amount = expenseDetail.Amount, PaidBy = expenseDetail.PaidBy, SplitEqually = expenseDetail.SplitEqually, ExpenseDate = expenseDetail.ExpenseDate, Attachment = expenseDetail.Attachment, Notes = expenseDetail.Notes, ExpenseDistributionModel = db.ExpenseDistribution.Where(y => y.ExpenseId == expenseDetail.ExpenseId).Select(y => new ExpenseDistributionModel { ExpenseDistributionId = y.ExpenseDistributionId, ExpenseId = y.ExpenseId, UserId = y.UserId, ShareAmount = y.ShareAmount, Share = y.Share, }).ToList(), PaidByUserModel = db.PaidByUser.Where(y => y.ExpenseId == expenseDetail.ExpenseId).Select(y => new PaidByUserModel { PaidByUserId = y.PaidByUserId, ExpenseId = y.ExpenseId, UserId = y.UserId, PaidAmount = y.PaidAmount, }).ToList() }; return(expenseModel); }
private void addExpensesButtonClick() { if (ExpensesNameData != null && ExpensesMoneyData != null && Helper.HelperFunctions.isNumericString(ExpensesMoneyData) == true) { ExpenseModel temp = new ExpenseModel(); temp.Name = ExpensesNameData; if (ExpensesMoneyData != null) { temp.AmountMoney = Int32.Parse(ExpensesMoneyData); } else { temp.AmountMoney = 0; } ExpensesList.Add(temp); } else if (Helper.HelperFunctions.isNumericString(ExpensesMoneyData) == false) { MessageBox.Show("Số tiền chỉ nhận giá trị số"); } else { MessageBox.Show("Vui lòng nhập đủ thông tin trước khi thêm!!!"); } ExpensesNameData = null; ExpensesMoneyData = null; OnPropertyChanged(nameof(ExpensesList)); OnPropertyChanged(nameof(ExpensesMoneyData)); OnPropertyChanged(nameof(ExpensesNameData)); }
public IEnumerator PostExpense(ExpenseModel expense) { var url = "http://192.168.1.85/AddExpenses.php"; var formData = new WWWForm(); yield return(RestService.Post(url, expense)); }
public async Task <bool> Delete(ExpenseModel nm) { try { var obj = RequestConverter.Instance.ConvertToNoteRequest(_userInformations.Guid, nm.ExpenseCollection.Guid, PossibleActions.Delete, new List <ExpenseModel>() { nm }); var res = await _dataService.PostExpense(obj); nm.PendingAction = !res.IsSuccessfull ? PendingAction.Remove : PendingAction.None; if (nm.ExpenseCollection.Expenses.Contains(nm)) { nm.ExpenseCollection.Expenses.Remove(nm); } else if (nm.ExpenseCollection.DeletedExpenses.Contains(nm)) { nm.ExpenseCollection.DeletedExpenses.Remove(nm); } if (nm.PendingAction != PendingAction.None) { nm.ExpenseCollection.DeletedExpenses.Add(nm); } return(await SaveExpenseCollectionsToStorage() && res.IsSuccessfull); } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } return(false); }
public async Task <ActionResult> CreateBill([FromBody] ExpenseModel bill) { if (!ModelState.IsValid) { return(BadRequest(new ApiGeneralResponse { Status = false })); } try { var newBill = await _ExpenseRepository.InsertBillAsync(bill); if (newBill == null) { return(BadRequest(new ApiGeneralResponse { Status = false })); } return(CreatedAtRoute("GetBillRoute", new { id = newBill.BillId }, new ApiGeneralResponse { Status = true, id = newBill.BillId })); } catch (Exception exp) { _Logger.LogError(exp.Message); return(BadRequest(new ApiGeneralResponse { Status = false })); } }
public IActionResult Expense() { ViewData["Message"] = "Set up the expenses here"; ExpenseModel model = new ExpenseModel(); return(View(model)); }
public ActionResult Edit(ExpenseModel expense) { if (ModelState.IsValid) { Expense expenseDb = db.Expenses.Find(expense.ExpenseId); expenseDb.Amount = expense.Amount; expenseDb.Type = expense.Type; expenseDb.TripId = expense.TripId; if (expense.Photo != null) { var photo = new Photo(); int length = expense.Photo.ContentLength; var tempImage = new byte[length]; expense.Photo.InputStream.Read(tempImage, 0, length); photo.ImageBytes = tempImage; photo.ContentType = expense.Photo.ContentType; photo.SourceFilename = expense.Photo.FileName; expenseDb.Photo = photo; } db.Entry(expenseDb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Invoice", "Expenses", new { id = expenseDb.InvoiceNumber })); } ViewBag.TripId = new SelectList(db.Trips, "TripId", "TripId", expense.TripId); return(View(expense)); }
public JsonResult SaveExpense(ExpenseModel model) { ExpenseDetails _details = new ExpenseDetails(); Tuple <Enums.CrudStatus, int> result = _details.SetExpense(model, CrudType.Insert); return(Json(ReturnAjaxAlertMessage(result.Item1, result.Item2).ToList(), JsonRequestBehavior.AllowGet)); }
//[OutputCache(Duration = 3600, VaryByParam = "id")] public ActionResult Delete(int?id) { var cats = GetAllItems(); ExpenseModel cm = cats.FirstOrDefault(x => x.Id == id.Value); return(View(cm)); }
public ActionResult Create(ExpenseModel expense) { if (ModelState.IsValid) { var newExpense = new Expense { Amount = expense.Amount, TripId = expense.TripId, Type = expense.Type }; var photo = new Photo(); if (expense.Photo != null) { int length = expense.Photo.ContentLength; var tempImage = new byte[length]; expense.Photo.InputStream.Read(tempImage, 0, length); photo.ImageBytes = tempImage; photo.ContentType = expense.Photo.ContentType; photo.SourceFilename = expense.Photo.FileName; } newExpense.Photo = photo; db.Expenses.Add(newExpense); db.SaveChanges(); return(RedirectToAction("Invoice/" + newExpense.InvoiceNumber)); } return(View(expense)); }
public async Task <IActionResult> Post([FromBody] ExpenseModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var expenseEntiry = new ExpenseEntity() { Name = value.Name, Amount = value.Amount, Category = value.Category, DateSubmitted = value.DateSubmitted }; var createdExpense = await _iExpenseDataAccess.AddExpense(expenseEntiry); return(Created($"/api/values/{createdExpense.Name}/{createdExpense.DateSubmitted.Month}/{createdExpense.DateSubmitted.Year}" , createdExpense)); } catch (Exception ex) { //TODO:Catch and log exception return(StatusCode((int)HttpStatusCode.InternalServerError, _configuration["HttpErroMessages:ServerError"])); } }
//[OutputCache(Duration = 3600, VaryByParam = "none")] public ActionResult Create() { int catId = 0; var cats = GetAllCategories(); var categories = cats.ToList(); categories.Insert(0, new CategoryModel { Name = "-- Please Select--", Id = 0 }); IEnumerable <SelectListItem> selectList = from c in categories select new SelectListItem { Selected = (c.Id == catId), Text = c.Name, Value = c.Id.ToString() }; ExpenseModel cm = new ExpenseModel { Id = 0, selectList = selectList }; return(View(cm)); }
public ActionResult Delete(int id, ExpenseModel expenseModel) { ExpenseModel expense = expenses.FirstOrDefault(x => x.ExpenseId == id); expenses.Remove(expense); return(RedirectToAction(nameof(Index))); }
public IActionResult PostExpense([FromBody] ExpenseModel model) { if (!ModelState.IsValid) { return(BadRequest("Model state is not valid.")); } if (!DateTime.TryParseExact(model.Date, this.DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime modelDate)) { return(BadRequest($"Date is not formated correctly. Please use: {DATE_FORMAT} format.")); } _context.Expenses.Add(new Entities.Expense { ExpenseCategoryId = model.ExpenseCategoryId, Description = model.Description, Date = modelDate, Ammount = model.Ammount, AddedBy = User.GetUserId(), Latitude = model.Latitude, Longitude = model.Longitude }); _context.SaveChanges(); return(Ok()); }
public int AddExpense(ExpenseModel ExpenseModel) { try { using (var _context = new DatabaseContext()) { ExpenseModel.HotelBills = ExpenseModel.HotelBills == null ? 0 : ExpenseModel.HotelBills; ExpenseModel.TravelBills = ExpenseModel.TravelBills == null ? 0 : ExpenseModel.TravelBills; ExpenseModel.MealsBills = ExpenseModel.MealsBills == null ? 0 : ExpenseModel.MealsBills; ExpenseModel.LandLineBills = ExpenseModel.LandLineBills == null ? 0 : ExpenseModel.LandLineBills; ExpenseModel.TransportBills = ExpenseModel.TransportBills == null ? 0 : ExpenseModel.TransportBills; ExpenseModel.MobileBills = ExpenseModel.MobileBills == null ? 0 : ExpenseModel.MobileBills; ExpenseModel.Miscellaneous = ExpenseModel.Miscellaneous == null ? 0 : ExpenseModel.Miscellaneous; _context.ExpenseModel.Add(ExpenseModel); _context.SaveChanges(); int id = ExpenseModel.ExpenseID; return(id); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Amount,CreationDate,UserId,CategoryId")] ExpenseModel expenseModel) { if (id != expenseModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _repository.UpdateExpense(expenseModel); } catch (DbUpdateConcurrencyException) { if (!(await ExpenseModelExists(expenseModel.Id))) { return(NotFound()); } else { return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(await _categoryRepository.GetCategories(), "Id", "CategoryName", expenseModel.CategoryId); return(View(expenseModel)); }
public IActionResult Edit(ExpenseModel obj) { // Didn't check for validation because it was bugging out _db.Expenses.Update(obj); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Post([FromBody] ExpenseModel expenseModel) { var modelstate = ModelState.Distinct(); if (!ModelState.IsValid) { return(BadRequest(modelstate.FirstOrDefault().Value)); } try { if (expenseModel == null) { return(BadRequest("invalid expense ")); } if (double.IsNaN(expenseModel.ExpenseAmount)) { return(BadRequest("expense amount field should have number value ")); } var expense = _mapper.Map <Expense>(expenseModel); await _expenseRepo.Insert(expense); var expenses = await GetExpenses(); return(Created("", expenses)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private void Expenselist_ItemTapped(object sender, ItemTappedEventArgs e) { if (CrossConnectivity.Current.IsConnected) { try { ExpenseModel data = (ExpenseModel)e.Item; Navigation.PushAsync(new ExpenseDetailPage(data)); } catch (Exception exce) { ExpenseModelDB data = (ExpenseModelDB)e.Item; Navigation.PushAsync(new ExpenseDetailPage(data)); } } else { try { ExpenseModelDB data = (ExpenseModelDB)e.Item; Navigation.PushAsync(new ExpenseDetailPage(data)); } catch { ExpenseModel data = (ExpenseModel)e.Item; Navigation.PushAsync(new ExpenseDetailPage(data)); } } }
public ActionResult Edit(int?id, bool?saved) { var items = GetAllItems(); var item = items.FirstOrDefault(x => x.Id == id.Value); int catId = item.ExpenseTypeId; var cats = GetAllCategories(); var categories = cats.ToList(); categories.Insert(0, new CategoryModel { Name = "-- Please Select--", Id = 0 }); IEnumerable <SelectListItem> selectList = from c in categories select new SelectListItem { Selected = (c.Id == catId), Text = c.Name, Value = c.Id.ToString() }; ExpenseModel cm = item; cm.selectList = selectList; cm.Saved = saved; return(View("Create", cm)); }
public void Action(AddItemInput message) { CheckItemInput(message); ItemModel item = null; if (message is AddGuestInput) { decimal amount = AmountConverter.Convert(message.Amount, false); item = new GuestModel(EventService.AddGuest(CurrentEvent.Id, null, message.Name, amount)); CurrentEvent.Guests.Add((GuestModel)item); Queue(ToItemOutput(item, ItemType.Guest)); } else if (message is AddExpenseInput) { decimal amount = AmountConverter.Convert(message.Amount, true); item = new ExpenseModel(EventService.AddExpense(CurrentEvent.Id, null, message.Name, amount)); CurrentEvent.Expenses.Add((ExpenseModel)item); Queue(ToItemOutput(item, ItemType.Expense)); } else { throw new InvalidCastException($"{message.GetType().Name} is not handled"); } CalculateOutcome(); QueueItemsCount(); QueueItemsAmount(); QueueOutcomeAvailable(); QueueOutcomeSummary(); QueueOutcomeGuests(); QueueItemSaved(); QueueEnableReset(); }
private int UpdateItem(ExpenseModel cm) { int id = 0; using (SqlConnection myConnection = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("ExpenseUpdate", myConnection)) { cmd.CommandType = CommandType.StoredProcedure; myConnection.Open(); //SqlParameter custId = cmd.Parameters.AddWithValue("@CustomerId", 10); cmd.Parameters.AddWithValue("@Id", cm.Id); cmd.Parameters.AddWithValue("@IsActive", cm.IsActive); cmd.Parameters.AddWithValue("@Amount", cm.Amount); cmd.Parameters.AddWithValue("@Description", cm.Description); cmd.Parameters.AddWithValue("@StaffId", cm.StaffId); cmd.Parameters.AddWithValue("@ExpenseTypeId", cm.ExpenseTypeId); try { int.TryParse(cmd.ExecuteScalar().ToString(), out id); } catch { } } } return(id); }
private ExpenseModel GetData() { ExpenseModel model = new ExpenseModel(); model.FirstName = "สนุก"; model.Lastname = "สุขสุนต์"; model.Date = new DateTime(2017, 5, 4); model.ExpenseItems.Add(new ExpenseItemModel() { Date = new DateTime(2017, 5, 4), Money = 200, Name = "เงินประจำวัน", Type = 0 }); model.ExpenseItems.Add(new ExpenseItemModel() { Date = new DateTime(2017, 5, 4), Money = 20, Name = "อาหารเช้า", Type = 1 }); model.ExpenseItems.Add(new ExpenseItemModel() { Date = new DateTime(2017, 5, 4), Money = 21, Name = "Mrt", Type = 1 }); model.ExpenseItems.Add(new ExpenseItemModel() { Date = new DateTime(2017, 5, 4), Money = 55, Name = "อาหารกลางวัน", Type = 1 }); model.ExpenseItems.Add(new ExpenseItemModel() { Date = new DateTime(2017, 5, 4), Money = 29, Name = "ขนมปังสังขยา", Type = 1 }); return(model); }
public IActionResult ExpenseLineRemove(ExpenseModel model, int index) { model.Item.Lines.RemoveAt(index); ModelState.Clear(); return(ExpenseView(model)); }
public async Task <ExpenseModel> GetExpense(int id) { ExpenseModel model = new ExpenseModel(); List <PayerModel> payers = new List <PayerModel>(); var expense = context.Expenses.ToList().FirstOrDefault(x => x.ExpenseId == id); var expenseinfolist = context.Expensesinfo.ToList().Where(x => x.ExpenseId == id); var sharelist = context.Shareinfo.ToList().Where(x => x.ExpenseId == id); foreach (var item in expenseinfolist) { PayerModel payerModel = new PayerModel(); var user = await UserManager.FindByIdAsync(item.UserId); payerModel.Payer = user; payerModel.Amount = item.PaidAmouunt; payers.Add(payerModel); } foreach (var item in sharelist) { var user = await UserManager.FindByIdAsync(item.UserId); item.User = user; } model.Shares = sharelist.ToList(); model.Expense = expense; model.Payers = payers; return(model); }
public RedirectToRouteResult Create(CreatePaymentViewModel viewModel) { CreatePaymentModel model = new CreatePaymentModel(); model.balanceSheetId = viewModel.balanceSheetId; model.Expenses = new List <ExpenseModel>(); for (int i = 0; i < viewModel.Expenses.Count; i++) { var item = viewModel.Expenses[i]; if (item.Paid) { ExpenseModel expenseModel = new ExpenseModel() { ExpenseId = item.Id, Paid = item.Paid, ChargeableId = item.ChargeableId }; model.Expenses.Add(expenseModel); } } _createPaymentCommand.Execute(model); return(RedirectToAction("Detail", "balanceSheet", model.balanceSheetId)); }
public ActionResult Entry(ExpenseViewModel expense) { ExpenseModel data = new ExpenseModel(); #region Income Model data maping data.Amount = expense.Amount; data.BankId = expense.BankId; data.Date = expense.Date; data.Particular = expense.Particular; data.ChequeNo = expense.ChequeNo; if (expense.isCash == 1) { data.Cash = true; } else { data.Cheque = true; } #endregion bool isSaved = ExpenseManager.SaveExpense(data); if (isSaved) { ViewBag.Message = "Expense Saved"; } ViewBag.BankList = BankManager.LoadBank(); return(View()); }
public async Task <ActionResult <ExpenseModel> > PostExpenseModel(ExpenseModel expenseModel) { _context.Expenses.Add(expenseModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetExpenseModel", new { id = expenseModel.Id }, expenseModel)); }
public async Task <IActionResult> PutExpenseModel(int id, ExpenseModel expenseModel) { if (id != expenseModel.Id) { return(BadRequest()); } _context.Entry(expenseModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExpenseModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// calculate GST and total excluding GST // non pure function private void CalculateGST(ExpenseModel expense) { // we are already asserting Total before calling this method // ReSharper disable once PossibleInvalidOperationException expense.TotalExcludingGST = Math.Round(expense.Total.Value * 100 / (100 + Constants.GST_PERCENT), 2); expense.GST = Math.Round((expense.Total.Value - expense.TotalExcludingGST), 2); }
public void Initialize() { Id = 1; var dataContext = new MemoryDataContext(); ExpenseModel = new ExpenseModel(dataContext); }
public void Initialize() { Id = 1; Expense = new Expense { Id = Id, Amount = 500, Description = "Test" }; DataContext = new MemoryDataContext(); ExpenseModel = new ExpenseModel(DataContext); }
public void Initialize() { Id = 1; Expense = new Expense { Id = Id }; var dataContext = new MemoryDataContext(); dataContext.Save(Expense); dataContext.Commit(); ExpenseModel = new ExpenseModel(dataContext); }