public ActionResult Create(QuotationApprovalViewModel model) { if (ModelState.IsValid) { QuotationApprovalRepository repo = new QuotationApprovalRepository(); TempData["Success"] = "Updated Successfully!"; //TempData["Id"] = 1; repo.UpdateSettings(model); } return(View(model)); }
public ActionResult Create() { QuotationApprovalRepository repo = new QuotationApprovalRepository(); QuotationApprovalViewModel model = new QuotationApprovalViewModel(); var amountSettings = repo.GetApprovalAmountSettings(); var approvalSettings = repo.GetApprovalSettings(); model.QuotationApprovalAmountSettings = new List <QuotationApprovalAmountSettings>(); model.QuotationApprovalSettings = new List <QuotationApprovalSettings>(); foreach (var item in amountSettings) { model.QuotationApprovalAmountSettings.Add(item); } foreach (var item in approvalSettings) { model.QuotationApprovalSettings.Add(item); } return(View(model)); }
public void UpdateSettings(QuotationApprovalViewModel model) { using (IDbConnection connection = OpenConnection(dataConnection)) { string sql = string.Empty; foreach (var item in model.QuotationApprovalAmountSettings) { sql += @"update QuotationApprovalAmountSettings set AmountFrom = '" + item.AmountFrom.ToString("#0.#0") + "', AmountTo = '" + item.AmountTo.ToString("#0.#0") + "' where ApprovalCode = " + item.ApprovalCode + ";"; } connection.Query(sql); sql = string.Empty; sql = "delete from QuotationApprovalSettings;"; connection.Query(sql); foreach (var item in model.QuotationApprovalSettings) { sql = @"insert into QuotationApprovalSettings(UserId, Approval1, Approval2, Approval3,Cancel) values (@UserId, @Approval1, @Approval2, @Approval3,@Cancel);"; connection.Query(sql, item); } } }