public async Task <ActionResult> FinanceOperation(SubmitPaymentViewModel viewModel) { var claim = await _claimsRepository.GetClaim(viewModel.ProjectId, viewModel.ClaimId); if (claim == null) { return(HttpNotFound()); } var error = WithClaim(claim); if (error != null) { return(error); } try { if (!ModelState.IsValid) { return(await Edit(viewModel.ProjectId, viewModel.ClaimId)); } await FinanceService.FeeAcceptedOperation(new FeeAcceptedOperationRequest() { ProjectId = claim.ProjectId, ClaimId = claim.ClaimId, Contents = viewModel.CommentText, FeeChange = viewModel.FeeChange, Money = viewModel.Money, OperationDate = viewModel.OperationDate, PaymentTypeId = viewModel.PaymentTypeId, }); return(RedirectToAction("Edit", "Claim", new { viewModel.ClaimId, viewModel.ProjectId })); } catch { return(await Edit(viewModel.ProjectId, viewModel.ClaimId)); } }
public ActionResult SubmitPayment(SubmitPaymentViewModel model) { var currentUser = GetAuthenticatedUser(); if (model.paymentType <= 0) { TempData["SubmitPaymentError"] = "انتخاب نوع پرداخت اجباری است."; return(Redirect("/invoice/payment/" + model.id)); } var invoice = _context.Invoice.Where(x => x.InvoiceStatusId == InvoiceStatus.Registered.Id && x.Id == model.id && x.UserId == currentUser.id).SingleOrDefault(); if (invoice == null) { return(HttpNotFound()); } if (invoice.InvoiceStatusId == InvoiceStatus.InProgress.Id) { return(Redirect("/invoice/detail/" + model.id)); } if (invoice.CouponId != null && !string.IsNullOrEmpty(model.coupon)) { Response couponResponse = null; couponResponse = CouponController.CheckCoupon(_context, currentUser, model.coupon, out Coupon coupon); if (couponResponse.status != ResponseStatus.Ok) { TempData["SubmitPaymentError"] = "انتخاب نوع پرداخت اجباری است."; return(Redirect("/invoice/payment/" + model.id)); } if (coupon.TypeId == CouponType.Amount.Id) { invoice.Price -= coupon.Value; } else if (coupon.TypeId == CouponType.Percentage.Id) { invoice.Price -= ((invoice.Price / 100) * coupon.Value); } if (invoice.Price < 0) { invoice.Price = 0; } invoice.CouponId = coupon.Id; } invoice.InvoiceStatusId = InvoiceStatus.InProgress.Id; invoice.PaymentTypeId = model.paymentType; invoice.ModifyUserId = currentUser.id; invoice.ModifyDate = GetDatetime(); invoice.ModifyIp = GetCurrentIp(); var invoiceLog = new InvoiceLog() { InvoiceId = invoice.Id, StatusId = InvoiceStatus.InProgress.Id, CreateUserId = currentUser.id, CreateDate = GetDatetime(), CreateIp = GetCurrentIp() }; _context.InvoiceLog.Add(invoiceLog); _context.SaveChanges(); return(Redirect("/invoice/detail/" + model.id)); }