public ActionResult EditGuarantorWithStatement(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 { // 1- Update Guaratntor GuarantorServices.Update(CurrentUser.Id, model.Guarantor, db); //2-Update GuarantorStatement model.GuarantorStatement.Guarantor = model.Guarantor.Id; GuarantorStatementServices.Update(CurrentUser.Id, model.GuarantorStatement, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed"); } 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()); } }
public ActionResult EditGuarantorWithStatement(int?id) { ViewBag.ModuleName = moduleName; ViewBag.Action = update; ViewBag.Update = update; ViewBag.Save = save; ViewBag.Back = back; Db db = new Db(DbServices.ConnectionString); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Guarantor guarantor = GuarantorServices.Get(id.Value, db); if (guarantor == null) { return(HttpNotFound()); } GuarantorStatement guarantorStatement = GuarantorStatementServices.Get(guarantor.Id, db); if (guarantorStatement == null) { return(HttpNotFound()); } ViewBag.EmployeeList = new SelectList(EmployeeServices.List(db), "Id", "Id_Name", guarantor.Employee); ViewBag.GuarantorStatusList = new SelectList(GuarantorStatusServices.List(db), "Id", "Name", guarantor.GuarantorStatus); ViewBag.ProductId = guarantor.RefundableProduct; GuarantorWithStatmentViewModel vm = new GuarantorWithStatmentViewModel(); vm.Guarantor = guarantor; vm.GuarantorStatement = guarantorStatement; return(PartialView(vm)); }
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")); } }