public ActionResult link(int loan_ID, int type) { try { var model_link = new LinkLoanDeductionsWithOtherManualPayment { Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date }; ViewBag.header = dbcontext.ManualPaymentTypes_Header.ToList().Select(m => new { Code = m.PaymentTypeCode + "------[" + m.PaymentTypeDesc + ']', ID = m.ID }); if (type == 0) { model_link.LoanInAdvanceSetupID = loan_ID; var loan = dbcontext.LoanInAdvanceSetup.FirstOrDefault(m => m.ID == loan_ID); model_link.LoanInAdvanceSetup = loan; model_link.NumberOfInstallments = 0; ViewBag.type = 0; return(View(model_link)); } else if (type == 1) { var link = dbcontext.LinkLoanDeductionsWithOtherManualPayment.FirstOrDefault(m => m.LoanInAdvanceSetupID == loan_ID); if (link != null) { ViewBag.type = 1; return(View(link)); } else { model_link.LoanInAdvanceSetupID = loan_ID; var loan = dbcontext.LoanInAdvanceSetup.FirstOrDefault(m => m.ID == loan_ID); model_link.LoanInAdvanceSetup = loan; model_link.NumberOfInstallments = 0; ViewBag.type = 0; return(View(model_link)); } } else { return(RedirectToAction("edit", new { id = loan_ID })); } } catch (Exception) { return(RedirectToAction("edit", new { id = loan_ID })); } }
public ActionResult link(LinkLoanDeductionsWithOtherManualPayment model, int type) { try { ViewBag.header = dbcontext.ManualPaymentTypes_Header.ToList().Select(m => new { Code = m.PaymentTypeCode + "------[" + m.PaymentTypeDesc + ']', ID = m.ID }); ViewBag.type = type; if (type == 0) { model.Created_By = User.Identity.Name; model.Created_Date = DateTime.Now.Date; } if (type == 1) { var link = dbcontext.LinkLoanDeductionsWithOtherManualPayment.FirstOrDefault(m => m.LoanInAdvanceSetupID == model.LoanInAdvanceSetupID); if (link != null) { dbcontext.LinkLoanDeductionsWithOtherManualPayment.Remove(link); dbcontext.SaveChanges(); model.Modified_By = User.Identity.Name; model.Modified_Date = DateTime.Now.Date; } } if (model.ManualPaymentTypes_DetailID == 0 || model.ManualPaymentTypes_HeaderID == 0 || model.LoanInAdvanceSetupID == 0) { return(View(model)); } model.LoanTypeCode = dbcontext.LoanInAdvanceSetup.FirstOrDefault(m => m.ID == model.LoanInAdvanceSetupID).LoanTypeCode; model.LoanInAdvanceSetup = null; model.PaymentTypeCode = dbcontext.ManualPaymentTypes_Header.FirstOrDefault(m => m.ID == model.ManualPaymentTypes_HeaderID).Type_Code; model.SalaryCodeID = dbcontext.ManualPaymentTypes_Detail.FirstOrDefault(m => m.ID == model.ManualPaymentTypes_DetailID).SalaryCodeID; dbcontext.LinkLoanDeductionsWithOtherManualPayment.Add(model); dbcontext.SaveChanges(); return(RedirectToAction("edit", new { id = model.LoanInAdvanceSetupID })); } catch (Exception e) { return(View(model)); } }