public async Task <IActionResult> CreatePayment([FromBody] PaymentCreateViewModel payment) { try { if (!ModelState.IsValid || payment == null) { return(BadRequest(new ErrorResponseViewModel { Message = ModelState.ErrorsToString() })); } var newPayment = Mapper.Map <Payment>(payment); if (!await _repository.CreatePayment(newPayment, _userManager.GetUserId(this.User))) { return(StatusCode(403, new ErrorResponseViewModel { Message = "Do not have premission for this action!" })); } if (await _repository.SaveChangesAsync()) { return(await GetPayment(newPayment.Id)); } } catch (Exception ex) { _logger.LogError($"Failed to create payment: {ex}"); } return(BadRequest(new ErrorResponseViewModel { Message = "Error while creating payment!" })); }
public ActionResult Edit(int id) { PaymentCreateViewModel vm = new PaymentCreateViewModel(); vm.Model = _paymentService.Get(id); return(View("Create", GetCreateViewModel(vm))); }
public IActionResult Create() { ViewBag.employees = _unitOfWork.Employees.GetAllEmployeesForPayroll(); ViewBag.taxYears = _unitOfWork.TaxYears.GetAll(); var viewModel = new PaymentCreateViewModel(); return(View(viewModel)); }
public async Task <ActionResult> PostPayment(PaymentCreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(model)); } var checklist = await _context.Checklists.Include(c => c.Table).Include(c => c.Orders).FirstOrDefaultAsync(c => c.Id == model.ChecklistId); if (checklist == null) { return(BadRequest()); } var payment = new Payment() { ChecklistId = model.ChecklistId, CouponId = model.CouponId, PaymentMethodId = model.PaymentMethodId, Amount = model.Amount, Total = model.Total, GrandTotal = model.GrandTotal, PaymentAt = DateTime.Now }; _context.Payments.Add(payment); foreach (var o in model.Orders) { var order = await _context.Orders.FindAsync(o.Id); order.IsPaid = true; order.PaymentId = payment.Id; } bool result = true; foreach (var o in checklist.Orders) { if (o.IsPaid == false) { result = false; } } if (result == true) { checklist.IsPaid = true; checklist.Table.IsAvailable = true; } await _context.SaveChangesAsync(); return(NoContent()); }
// GET: Payments/Create public async Task <IActionResult> Create() { var vm = new PaymentCreateViewModel() { InvoiceSelectList = new SelectList(await _bll.Invoices.AllAsync(), nameof(BLL.App.DTO.Invoice.Id), nameof(BLL.App.DTO.Invoice.Id)), }; return(View(vm)); }
public static PaymentCreateDto ToDto(this PaymentCreateViewModel source) { return(new PaymentCreateDto { CreateDate = source.CreateDate, FullName = source.FullName, PhoneNumber = source.PhoneNumber, Price = source.Price, RecordId = source.RecordId, Type = source.Type }); }
public ActionResult Create(int id) { PaymentCreateViewModel vm = new PaymentCreateViewModel() { Model = new PaymentBasicViewModel() { OrderID = id, PaymentDate = DateTime.Now, Currency = "PLN", ExchangeRate = 1 } }; return(View(GetCreateViewModel(vm))); }
public async Task <IActionResult> Create(PaymentCreateViewModel vm) { if (ModelState.IsValid) { _bll.Payments.Add(vm.Payment); await _bll.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.InvoiceSelectList = new SelectList(await _bll.Invoices.AllAsync(), nameof(BLL.App.DTO.Invoice.Id), nameof(BLL.App.DTO.Invoice.Id), vm.Payment.InvoiceId); return(View(vm)); }
public IActionResult Index(PaymentCreateViewModel model) { var serviceResult = _userService.CreatePayment(model.ToDto()); if (serviceResult.IsSuccess) { // برو به بانک return(RedirectPermanent($"/Payment/Index/{serviceResult.Data}")); } ViewBag.id = model.RecordId; ViewBag.type = model.Type; AddErrors(serviceResult); return(View(model)); }
public ActionResult Edit(PaymentCreateViewModel viewModel) { if (ModelState.IsValid) { ServiceResult result = _paymentService.Update(viewModel.Model); if (result.Status) { AddSuccessEditedToastMessage(); return(RedirectToAction("Details", "Order", new { id = viewModel.Model.OrderID })); } else { AddServiceErrorToastMessage(result); return(View("Create", GetCreateViewModel(viewModel))); } } return(View("Create", GetCreateViewModel(viewModel))); }
public string MakePayment(int RouteId) { //var routeToMakePayment = _routeService.getRouteDetail(RouteId); //var customerInfor = _customerService.FindCustomerById(routeToMakePayment.CutomerId); //var creditCardToMakePayment = _creditCardService.GetCardToPayment(routeToMakePayment.CustomerId); var routeToMakePayment = _routeRepository.Get(x => x.Id == RouteId); var customerInfor = _customerRepository.Get(x => x.Id == routeToMakePayment.CustomerId); var creditCardToMakePayment = _creditCardRepository.Get(x => x.Deleted == false && x.CustomerId == routeToMakePayment.CustomerId && x.Isdefault == true); //Stripe charge money StripeConfiguration.SetApiKey(SETTING.Value.SecretStripe); var options = new ChargeCreateOptions { Amount = Convert.ToInt64(routeToMakePayment.TotalAmount * 100), Currency = "usd", Description = customerInfor.FullName.ToUpper() + "-" + customerInfor.Email + "-" + customerInfor.PhoneNumber + " buy Route Code: " + routeToMakePayment.Code, SourceId = creditCardToMakePayment.CardId, // obtained with Stripe.js, CustomerId = customerInfor.StripeId, }; var service = new ChargeService(); service.ExpandBalanceTransaction = true; Charge charge = service.Create(options); PaymentCreateViewModel model = new PaymentCreateViewModel(); model.RouteId = routeToMakePayment.Id; model.CreditCartId = creditCardToMakePayment.Id; model.Description = "You bought route " + routeToMakePayment.Code + ". Thank you for using our service."; model.Amount = routeToMakePayment.TotalAmount; model.Status = PaymentStatus.Success; model.StripeChargeId = charge.Id; model.FeeAmount = Convert.ToDecimal(charge.BalanceTransaction.Fee) / 100; var payment = _mapper.Map <PaymentCreateViewModel, Payment>(model); //map từ ViewModel qua Model _paymentRepository.Add(payment); _unitOfWork.CommitChanges(); return(""); }
public async Task <IActionResult> Create() { ViewBag.employees = (await _unitOfWork.EmployeeRepository.GetAllAsync()) .Select(employee => new SelectListItem() { Text = employee.FirstName + " " + employee.LastName, Value = employee.Id.ToString() }); ViewBag.taxYears = (await _unitOfWork.TaxYearRepository.GetAllAsync()) .Select(taxYears => new SelectListItem() { Text = taxYears.YearOfTax, Value = taxYears.Id.ToString() }); var model = new PaymentCreateViewModel(); return(View(model)); }
public IActionResult Create(PaymentCreateViewModel viewModel) { if (ModelState.IsValid) { var paymentRecord = new PaymentRecord() { Id = viewModel.Id, EmployeeId = viewModel.EmployeeId, Firstname = _unitOfWork.Employees.Get(viewModel.EmployeeId).FirstName, Lastname = _unitOfWork.Employees.Get(viewModel.EmployeeId).LastName, PaymentDate = viewModel.PaymentDate, PaymentMonth = viewModel.PaymentMonth, TaxYearId = viewModel.TaxYearId, TaxCode = viewModel.TaxCode, HourlyRate = viewModel.HourlyRate, HoursWorked = viewModel.HoursWorked, ContractualHours = viewModel.ContractualHours, OvertimeHourse = overTimeHourse = _unitOfWork.Payments.OverTimeHourse(viewModel.HoursWorked, viewModel.ContractualHours), ContractualEarnings = contractualEarnings = _unitOfWork.Payments.ContractualEarnings(viewModel.ContractualEarnings, viewModel.HoursWorked, viewModel.HourlyRate), OvertimeEarnings = overTimeEarnings = _unitOfWork.Payments.OverTimeEarnings(_unitOfWork.Payments.OverTimeRate(viewModel.HourlyRate), overTimeHourse), TotalEarnings = totalEarnings = _unitOfWork.Payments.TotalEarnings(overTimeEarnings, contractualEarnings), Tax = tax = _unitOfWork.Taxes.TaxAmount(totalEarnings), UnionFee = unionFee = _unitOfWork.Employees.UnionFees(viewModel.EmployeeId), StudentLoanCompany = studentLoan = _unitOfWork.Employees.StudentLoanPayment(viewModel.EmployeeId, totalEarnings), InsuranceContribution = insurance = _unitOfWork.Insurences.InsuranceContribution(totalEarnings), TotalDeduction = totalDeduction = _unitOfWork.Payments.TotalDeduction(tax, insurance, studentLoan, unionFee), NetPayment = _unitOfWork.Payments.NetPay(totalEarnings, totalDeduction) }; _unitOfWork.Payments.Create(paymentRecord); _unitOfWork.Complete(); return(RedirectToAction(nameof(Index))); } ViewBag.employees = _unitOfWork.Employees.GetAllEmployeesForPayroll(); ViewBag.taxYears = _unitOfWork.TaxYears.GetAll(); return(View()); }
public async Task <IActionResult> Create(PaymentCreateViewModel model) { decimal overtimeHrs, contractualEarnings, overtimeEarnings, totalEarnings, tax, unionFee, studentLoan, nationalInsurance, totalDeduction; if (!ModelState.IsValid) { ViewBag.employees = (await _unitOfWork.EmployeeRepository.GetAllAsync()) .Select(employee => new SelectListItem() { Text = employee.FirstName + " " + employee.LastName, Value = employee.Id.ToString() }); ViewBag.taxYears = (await _unitOfWork.TaxYearRepository.GetAllAsync()) .Select(taxYears => new SelectListItem() { Text = taxYears.YearOfTax, Value = taxYears.Id.ToString() }); return(View()); } var paymentRecord = new PaymentRecord(); paymentRecord.Id = model.Id; paymentRecord.EmployeeId = model.EmployeeId; paymentRecord.Employee = await _unitOfWork.EmployeeRepository.GetByIdAsync(model.EmployeeId); paymentRecord.Employee.NationalInsuranceNo = (await _unitOfWork.EmployeeRepository .GetByIdAsync(model.EmployeeId)).NationalInsuranceNo; paymentRecord.PayDate = model.PayDate; paymentRecord.PayMonth = model.PayMonth; paymentRecord.TaxYearId = model.TaxYearId; paymentRecord.TaxCode = model.TaxCode; paymentRecord.HourlyRate = model.HourlyRate; paymentRecord.HoursWorked = model.HoursWorked; paymentRecord.ContractualHours = model.ContractualHours; paymentRecord.OvertimeHours = overtimeHrs = _paymentComputeService .OvertimeHours(model.HoursWorked, model.ContractualHours); paymentRecord.ContractualEarnings = contractualEarnings = _paymentComputeService .ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate); paymentRecord.OvertimeEarnings = overtimeEarnings = _paymentComputeService .OvertimeEarnings(_paymentComputeService.OvertimeRate(model.HourlyRate), model.OvertimeHours); paymentRecord.TotalEarnings = totalEarnings = _paymentComputeService .TotalEarnings(overtimeEarnings, contractualEarnings); paymentRecord.Tax = tax = _taxService.TaxAmount(totalEarnings); paymentRecord.UnionFee = unionFee = _taxService.TaxAmount(totalEarnings); paymentRecord.SLC = studentLoan = await _paymentComputeService .StudentLoanRepaymentAmountAsync(model.EmployeeId, totalEarnings); paymentRecord.NIC = nationalInsurance = _nIContributionService .CalculateNIContribution(totalEarnings); paymentRecord.TotalDeduction = totalDeduction = _paymentComputeService .TotalDeductuon(tax, nationalInsurance, studentLoan, unionFee); paymentRecord.NetPayment = _paymentComputeService.NetPay(totalEarnings, totalDeduction); await _unitOfWork.PaymentRepository.AddAsync(paymentRecord); if (await _unitOfWork.SaveAsync()) { Alert("Successfully created!", NotificationType.success); } return(RedirectToAction(nameof(Index))); }
private PaymentCreateViewModel GetCreateViewModel(PaymentCreateViewModel currModel) { return(currModel); }