public ActionResult UpdatePaymentTypes(List <QAUtil.Models.PaymentTypes> grid, FormCollection form) { int churchId = Convert.ToInt32(form["church"]); int featureID = grid[0].FeatureID; ViewData["churchId"] = churchId; ViewData["dataSource"] = form["dataSource"]; var dataContext = new PaymentTypesDataContext(Common.FetchDBConnectionString(form["dataSource"])); foreach (var item in grid) { bool enabled = item.ENABLED; int pp_type_id = item.PP_TYPE_ID; // Enable or disable the module if (enabled) { if (!dataContext.PP_CHURCH_TYPE_PROCESSORs.Any(c => c.PP_TYPE_ID == item.PP_TYPE_ID && c.CHURCH_ID == churchId && c.FEATURE_ID == item.FeatureID)) { PP_CHURCH_TYPE_PROCESSOR cm = new PP_CHURCH_TYPE_PROCESSOR() { CHURCH_ID = churchId, PP_TYPE_ID = item.PP_TYPE_ID, FEATURE_ID = item.FeatureID, CREATED_DATE = DateTime.Now, LAST_UPDATED_DATE = DateTime.Now, CREATED_BY_LOGIN = HttpContext.User.Identity.Name, PP_Merchant_Provider_ID = item.PP_TYPE_ID == 19 ? 2 : 1 }; dataContext.PP_CHURCH_TYPE_PROCESSORs.InsertOnSubmit(cm); dataContext.SubmitChanges(); } } else { if (dataContext.PP_CHURCH_TYPE_PROCESSORs.Any(c => c.PP_TYPE_ID == item.PP_TYPE_ID && c.CHURCH_ID == churchId && c.FEATURE_ID == item.FeatureID)) { dataContext.PP_CHURCH_TYPE_PROCESSORs.DeleteOnSubmit(dataContext.PP_CHURCH_TYPE_PROCESSORs.Where(cm => cm.PP_TYPE_ID == item.PP_TYPE_ID && cm.CHURCH_ID == churchId && cm.FEATURE_ID == featureID).Select(cm => cm).Single()); dataContext.SubmitChanges(); } } } return(RedirectToAction("PaymentTypes", new { dataSource = ViewData["dataSource"], churchId = ViewData["churchId"], feature = featureID == 6 ? "Online Giving 1.0" : "Online Giving 2.0" })); }
public ActionResult PaymentTypes(string dataSource, string churchId, string feature = "Online Giving 1.0") { int church = Convert.ToInt32(churchId); int featureID = feature == "Online Giving 1.0" ? 6 : 10; ViewData["dataSource"] = dataSource; ViewData["churchID"] = church; var dataContext = new PaymentTypesDataContext(Common.FetchDBConnectionString(dataSource)); var paymentTypes = from types in dataContext.PP_TYPEs orderby types.PP_TYPE_ID join payTypes in dataContext.PP_CHURCH_TYPE_PROCESSORs on new { types.PP_TYPE_ID, f1 = church, f2 = featureID } equals new { payTypes.PP_TYPE_ID, f1 = payTypes.CHURCH_ID, f2 = payTypes.FEATURE_ID } into mod from x in mod.DefaultIfEmpty() select new QAUtil.Models.PaymentTypes { ENABLED = x.PP_TYPE_ID != null ? true : false, PP_TYPE_ID = types.PP_TYPE_ID, PaymentType = types.PP_TYPE_NAME, FeatureID = featureID }; return(View(paymentTypes)); }