public ActionResult Create([Bind(Include = "Product, PaymentPeriod, Installment, NetAmount, ProfitAmount, SyrianPoundRounds")] RefundableProduct refundableProduct) { Db db = new Db(DbServices.ConnectionString); if (ModelState.IsValid) { try { RefundableProductServices.Insert(CurrentUser.Id, refundableProduct, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed"); return(RedirectToAction("Index")); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } ViewBag.ProductList = new SelectList(ProductServices.List(db), "Id", "Notes"); return(View(refundableProduct)); }
public ActionResult Edit(int?id) { LoanRequestViewModel vm = new LoanRequestViewModel(); try { Db db = new Db(DbServices.ConnectionString); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = ProductServices.Get(id.Value, db); Request request = RequestServices.Get(id.Value, db); LoanRequest loanRequest = LoanRequestServices.Get(id.Value, db); RefundableProduct refundableProduct = RefundableProductServices.Get(id.Value, db); if (product == null || request == null || loanRequest == null || refundableProduct == null) { return(HttpNotFound()); } // For Product //ViewBag.EmployeeList = new SelectList(EmployeeServices.List(db), "Id", "Id_Name", product.Employee); ViewBag.ProductTypeList = new SelectList(ProductTypeServices.List(db), "Id", "Name", product.ProductType); // For Request //We need to customise the droplist for two options ViewBag.BypassStatusList = new SelectList(BypassStatusServices.List(db).Where((c => (c.Id == 0 || c.Id == 2))), "Id", "Name"); EmployeeProductCalculatorFilter f = new EmployeeProductCalculatorFilter(); f.EmployeeId = product.Employee; f.ProductTypeId = (short)product.ProductType; f.Amount = (decimal)request.Amount; f.Period = (short)refundableProduct.PaymentPeriod; EmployeeProductCalculatorResult result = db.EmployeeProductCalculatorFirstOrDefault(f); if (result != null) { ViewBag.Calculations = result; } vm.RequestProduct = product; vm.Request = request; vm.LoanRequest = loanRequest; vm.RequestProductProductRefundableProduct = refundableProduct; } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } return(View(vm)); }
// GET: RefundableProduct/Delete/5 public ActionResult Delete(Nullable <int> id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Db db = new Db(DbServices.ConnectionString); RefundableProduct refundableProduct = RefundableProductServices.Get(id.Value, db); if (refundableProduct == null) { return(HttpNotFound()); } return(View(refundableProduct)); }
// GET: RefundableProduct/Edit/5 public ActionResult Edit(Nullable <int> product) { Db db = new Db(DbServices.ConnectionString); if (product == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RefundableProduct refundableProduct = RefundableProductServices.Get(product.Value, db); if (refundableProduct == null) { return(HttpNotFound()); } ViewBag.ProductList = new SelectList(ProductServices.List(db), "Id", "Notes", refundableProduct.Product); return(View(refundableProduct)); }
public ActionResult CreateGuarantorWithStatement(GuarantorWithStatmentViewModel model) { try { Db db = new Db(DbServices.ConnectionString); if (!(db.Connection.State == ConnectionState.Open)) { db.Connection.Open(); } db.Transaction = db.Connection.BeginTransaction(); if (ModelState.IsValid) { try { model.Guarantor.GuarantorStatus = (int)GuarantorStatusEnum.New; // 1- Add Guaratntor Guarantor g = GuarantorServices.Insert(CurrentUser.Id, model.Guarantor, db); //2-Add GuarantorStatement model.GuarantorStatement.Guarantor = g.Id; GuarantorStatement gs = GuarantorStatementServices.Insert(CurrentUser.Id, model.GuarantorStatement, db); Request r = db.RequestGet(model.Guarantor.RefundableProduct); RefundableProduct rp = db.RefundableProductGet(model.Guarantor.RefundableProduct); //Calculate Solvency GetEmployeeSolvencyFilter filter = new GetEmployeeSolvencyFilter() { EmployeeId = model.Guarantor.Employee, Amount = r.Amount, Date = r.Date, Installment = rp.Installment, GrossSalary = model.GuarantorStatement.GrossSalary, NetSalary = model.GuarantorStatement.NetSalary }; GetEmployeeSolvencyResult solvencyResult = db.GetEmployeeSolvencyFirstOrDefault(filter); // update notes field at Guarantor string result = getResult(solvencyResult); g.Notes = result; GuarantorServices.Update(CurrentUser.Id, g, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed"); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } if (db.Transaction != null) { db.Transaction.Commit(); } return(RedirectToAction("Details", new { id = model.Guarantor.RefundableProduct })); } catch { return(View("Details")); } }