public async Task <JsonResult> RemoveExpense(ExpenseVM expense) { Response r = await Repository.RemoveExpense(expense); // List<UserVM> employees = ((IEnumerable)r.Value).Cast<UserVM>().ToList(); ; return(Json(r, JsonRequestBehavior.AllowGet)); }
public static ExpensesVM GetAll(BPARepo bpaRepo, int budgetId) { var expenses = bpaRepo.Expense.GetAll().Where(x => x.BudgetId == budgetId).ToList(); var expenseVMs = new List<ExpenseVM>(); foreach (var expense in expenses) { var expenseVM = new ExpenseVM() { Id = expense.Id, BudgetId = expense.BudgetId, ExpenseName = expense.ExpenseName, ExpenseAmount = expense.ExpenseAmount, Units = expense.Units, ExpenseDate = expense.ExpenseDate, }; expenseVMs.Add(expenseVM); } var model = new ExpensesVM() { Expenses = expenseVMs, BudgetId = budgetId, }; return model; }
//GET UPDATE public IActionResult Update(int?id) { if (id == null || id == 0) { return(NotFound()); } var expense = _context.Expenses.Find(id); if (expense == null) { return(NotFound()); } ExpenseVM expenseVm = new ExpenseVM() { Expense = expense, ExpenseTypes = _context.ExpenseTypes.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; return(View(expenseVm)); }
public ActionResult SaveExpense(ExpenseVM view) { ModelState.Remove("Id"); if (ModelState.IsValid) { if (view.Id == 0) { _expenseRepository.AddToDatabase(view.MapToModel()); TempData["expenseCreatedOrUpdatedMessage"] = "Expense successfully created!"; } else { _expenseRepository.UpdateInDatabase(view.MapToModel(), view.Id); TempData["expenseCreatedOrUpdatedMessage"] = "Expense successfully updated!"; } _expenseRepository.Save(); // calculate ExchangeRate for ExpenseSum if neccessary var travelReport = _travelReportRepository.FindById(view.TravelReportId).MapToView(); var country = _countryAllowanceRepository .GetAllFromDatabaseEnumerable() .Where(c => c.Id == travelReport.CountryAllowanceId) .SingleOrDefault() .MapToView(); travelReport.ExpenseSum = 0; CalculateExpenseSum(travelReport); } return(RedirectToAction("Edit/" + view.TravelReportId)); }
public ActionResult Create() { ExpenseVM viewModel = new ExpenseVM(); // viewModel = poulateDropDownList(viewModel); return(View(viewModel)); }
public async Task <Response> RemoveExpense(ExpenseVM expense) { try { var DTO = await _db.Expenses.Where(x => x.Id == expense.Id).FirstOrDefaultAsync(); _db.Expenses.Remove(DTO); int result = await _db.SaveChangesAsync(); if (result == 1) { // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result)); } else { return(GenericResponses <int> .ResponseStatus(true, Constant.MSGFailed, (int)Constant.httpStatus.NoContent, result)); } } catch (Exception e) { return(GenericResponses <int> .ResponseStatus(true, e.Message, (int)Constant.httpStatus.NoContent, 0)); } }
// GET-Update public IActionResult Update(int?id) { ExpenseVM expenseVM = new ExpenseVM() { Expense = new Expense(), TypeDropDown = _db.ExpenseTypes.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; if (id == null || id == 0) { return(NotFound()); } //var obj = _db.Expenses.Find(id); //if (obj == null) //{ // return NotFound(); //} expenseVM.Expense = _db.Expenses.Find(id); if (expenseVM.Expense == null) { return(NotFound()); } return(View(expenseVM)); }
public async Task <Response> AddExpense(ExpenseVM expense) { var Dto = Mapper.Map <ExpenseVM, Expense>(expense); Expense Exist = await _db.Expenses.Where(x => x.Expense1.Trim() == expense.Expense1.Trim()).FirstOrDefaultAsync(); if (Exist != null) { return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoAlreadyExist, (int)Constant.httpStatus.NoContent, 0)); } _db.Expenses.Add(Dto); int result = await _db.SaveChangesAsync(); if (result == 1) { // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>()); return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result)); } else { return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoLoginFailed, (int)Constant.httpStatus.NoContent, result)); } }
// Expense // Transaction // Invoice public async Task <WrapperExpenseListVM> Add(ExpenseVM vm) { var invoiceToAdd = _utilService.GetMapper().Map <ExpenseVM, Invoice>(vm); var ExpenseToAdd = _utilService.GetMapper().Map <ExpenseVM, Expense>(vm); var transactionToAdd = _utilService.GetMapper().Map <ExpenseVM, TblTransaction>(vm); //string uniqueIdTask =await _repositoryWrapper.Expense.GetUniqueId(); //// Todo need to aandle unique id from db //entityToAdd.UniqueId = uniqueIdTask; _repositoryWrapper.Invoice.Create(invoiceToAdd); ExpenseToAdd.InvoiceId = invoiceToAdd.Id; _repositoryWrapper.Expense.Create(ExpenseToAdd); transactionToAdd.InvoiceId = invoiceToAdd.Id; _repositoryWrapper.Transaction.Create(transactionToAdd); Task <int> t1 = _repositoryWrapper.Expense.SaveChangesAsync(); Task <int> t2 = _repositoryWrapper.Invoice.SaveChangesAsync(); Task <int> t3 = _repositoryWrapper.Transaction.SaveChangesAsync(); await Task.WhenAll(t1, t2, t3); var dataParam = new GetDataListVM() { FactoryId = vm.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperExpenseListVM data = await GetListPaged(dataParam); return(data); }
private void DateListItemSelected(object sender, SelectionChangedEventArgs e) { if (listBoxobj.SelectedIndex != -1) { ExpenseVM listitem = listBoxobj.SelectedItem as ExpenseVM;//Get slected listbox item contact ID Frame.Navigate(typeof(DailyPage), listitem.GetDateOnly()); } }
public async Task <JsonResult> AddExpense(ExpenseVM expense) { expense.EcomID = (int)Session["Comp"]; Response r = await Repository.AddExpense(expense); // List<UserVM> employees = ((IEnumerable)r.Value).Cast<UserVM>().ToList(); ; return(Json(r, JsonRequestBehavior.AllowGet)); }
public IActionResult UpdatePost(ExpenseVM model) { if (ModelState.IsValid) { _context.Expenses.Update(model.Expense); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Create(ExpenseVM expenseVM) { if (ModelState.IsValid) { _db.Expenses.Add(expenseVM.Expense); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(expenseVM)); }
public IActionResult Create(ExpenseVM model) { if (ModelState.IsValid) { _context.Add(model.Expense); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Create(ExpenseVM obj) { if (ModelState.IsValid) { _dbContext.Expenses.Add(obj.Expense); _dbContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(obj)); }
public IActionResult Add() { var vm = new ExpenseVM { ExpenseDate = DateTime.Today }; PopulateLists(vm); return(View("Add", vm)); }
public IActionResult Update(ExpenseVM obj) { if (ModelState.IsValid) { _db.Expenses.Update(obj.Expense); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(obj)); }
public IActionResult Expense(ExpenseVM expense) { var userName = HttpContext.User.Identity.Name; var userId = _userService.All().First(u => u.Login == userName).Id; _moneyOperationService.Expense(_postgresContext, expense.MoneyWorkerId, expense.Sum, _moneyOperationService.PaymentTypeByMoneyWorker(expense.MoneyWorkerId), expense.ExpenseCategory, expense.Comment, _shopService.ShopByUserId(_db, userId).Id, expense.For); return(RedirectToAction("Index")); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // parameter as data m_CurrentExpense = e.Parameter as ExpenseVM; // fill data into widgets w_DateOfExpense.Date = new DateTimeOffset(m_CurrentExpense.GetDateOnly()); w_AmountOfExpense.Text = m_CurrentExpense.Amount.ToString(); w_AmountOfExpense.Focus(FocusState.Keyboard); }
private void PopulateLists(ExpenseVM model) { var list = _expensesService.GetExpenseTypes().Select(x => new SelectListItem { Text = x.ExpenseType, Value = x.Id.ToString() }).ToList(); model.ExpenseTypes = list; }
public ActionResult CreateExpenseVM(int?id) { var day = db.Days.Find(id); var ExpenseVM = new ExpenseVM() { DayId = id, day = day, TripId = day.TripID }; ViewBag.budgets = new SelectList(day.Trip.Budgets, "Id", "Department.Name"); return(View(ExpenseVM)); }
// EXPENSE public ActionResult CreateExpense(int travelReportId) { FillDropDownValuesForOfficialCurrency(); FillDropDownValuesForExpenseCategory(); var expense = new ExpenseVM { TravelReportId = travelReportId }; return(PartialView("_CreateExpense", expense)); }
public ActionResult Edit(int id) { ExpenseVM viewModel = new ExpenseVM(); CRUDOperation dataOperations = new CRUDOperation(); tbl_ExpenseChannel tblItem = dataOperations.GetExpenseChannelById(id); viewModel.ExpenseChannelID = id; viewModel.ShortName = tblItem.ShortName; viewModel.ExpenseName = tblItem.ExpenseName; viewModel.Expense = tblItem.Expense; viewModel.ExpenseFactor = tblItem.ExpenseFactor; return(View(viewModel)); }
// GET: ExpenseController/Create public IActionResult Create() { var expenseVM = new ExpenseVM { Expense = new Expense(), TypeDropDown = _db.ExpenseTypes.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; return(View(expenseVM)); }
public IActionResult Create() { ExpenseVM expenseVm = new ExpenseVM() { Expense = new Expense(), ExpenseTypes = _context.ExpenseTypes.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; return(View(expenseVm)); }
public ActionResult UpdateExpense(ExpenseVM model) { try { ExpenseServices.Update(model, BPARepo); return(RedirectToAction("Expense", new { budgetId = model.BudgetId })); } catch (Exception ex) { SetViewError(ex); return(View(model)); } }
public static ExpenseVM GetById(int id, BPARepo bpaRepo) { var expense = bpaRepo.Expense.GetById(id); var model = new ExpenseVM() { Id = expense.Id, BudgetId = expense.BudgetId, ExpenseName = expense.ExpenseName, ExpenseAmount = expense.ExpenseAmount, Units = expense.Units, ExpenseDate = expense.ExpenseDate, }; return(model); }
private ExpenseVM CreateVM() { ExpenseVM objVM = new ExpenseVM() { Expense = new Expense(), CategoryDropDown = _dbContext.ExpenseCategories. Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }) }; return(objVM); }
private IActionResult Get(int?id) { if ((id == null) || (id == 0)) { return(NotFound()); } ExpenseVM obj = this.CreateVM(); obj.Expense = _dbContext.Expenses.Find(id); if (obj.Expense == null) { return(NotFound()); } return(View(obj)); }
public ActionResult Edit(ExpenseVM viewModel) { try { var UserProfile = (UserProfileSessionData)this.Session["UserProfile"]; if (UserProfile != null) { if (ModelState.IsValid) { tbl_ExpenseChannel item = new tbl_ExpenseChannel() { ID = viewModel.ExpenseChannelID, ShortName = viewModel.ShortName, ExpenseName = viewModel.ExpenseName, Expense = viewModel.Expense, ExpenseFactor = viewModel.ExpenseFactor, UpdateDate = DateTime.Now, UpdateUser = UserProfile.UserId }; CRUDOperation dataOperations = new CRUDOperation(); tbl_ExpenseChannel dbItem = dataOperations.UpdateExpenseChannel(item); if (dbItem != null) { TempData["success"] = "Ok"; TempData["message"] = "Məlumatlar uğurla dəyişdirildi"; return(RedirectToAction("Index")); } else { TempData["success"] = "notOk"; TempData["message"] = "Məlumatlar dəyişdirilərkən xəta baş verdi"; return(RedirectToAction("Index")); } } } throw new ApplicationException("Invalid model"); } catch (ApplicationException ex) { return(View(viewModel)); } }