public ActionResult SMS_Template_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Deca_SMS_Template> listTemplate) { IEnumerable <Deca_SMS_Template> u = new Deca_SMS_Template[] { }; if (asset.Create) { using (var dbConn = OrmliteConnection.openConn()) { if (listTemplate != null && ModelState.IsValid) { foreach (var smstem in listTemplate) { var list = dbConn.FirstOrDefault <Deca_SMS_Template>("ID=" + smstem.ID); list.UpdatedAt = DateTime.Now; list.IsActive = smstem.IsActive; list.CreatedBy = currentUser.UserName; list.UpdatedBy = currentUser.UserName; list.CreatedAt = DateTime.Now; list.MaxNumber = smstem.MaxNumber; list.Message = smstem.Message; list.Title = smstem.Title; dbConn.Update(list); } return(Json(new { success = true })); } ModelState.AddModelError("", "Model not valid"); return(Json(u.ToDataSourceResult(request, ModelState))); } } else { ModelState.AddModelError("", "You don't have permission to create record"); return(Json(u.ToDataSourceResult(request, ModelState))); } }
public ActionResult SendMessage(string maxNum, string message, string title, string roles, string id) { using (var dbConn = OrmliteConnection.openConn()) { if (id == "0") { //Neu co id= 0 thi insert Deca_SMS_Template template = new Deca_SMS_Template(); template.Message = message.ToString(); template.MaxNumber = int.Parse(maxNum.ToString()); template.Title = title; template.IsActive = true; template.UpdatedBy = currentUser.UserName; template.CreatedAt = DateTime.Now; template.CreatedBy = currentUser.UserName; template.UpdatedAt = DateTime.Now; string[] sep = { "," }; var Arr = roles.Split(sep, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < Arr.Length; i++) { if (Arr[i].ToString() == "All") { template.Roles = ""; template.Roles = "All"; dbConn.Insert(template); return(Json(new { data = "Send", success = "Sucessfull" })); } else { template.Roles = roles; } } dbConn.Insert(template); return(Json(new { data = "Send", success = "Sucessfull" })); } else { //id != 0 updates var w = new Deca_SMS_Template(); var list = dbConn.FirstOrDefault <Deca_SMS_Template>("ID=" + id); list.CreatedAt = DateTime.Now; list.CreatedBy = currentUser.UserName; list.UpdatedBy = currentUser.UserName; list.UpdatedAt = DateTime.Now; list.MaxNumber = int.Parse(maxNum); list.Message = message; list.Title = title; string[] sep = { "," }; var Arr = roles.Split(sep, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < Arr.Length; i++) { if (Arr[i].ToString() == "All") { list.Roles = ""; list.Roles = "All"; dbConn.Update(list); return(Json(new { data = "Send", success = "Update Sucessfull" })); } else { list.Roles = roles; } } dbConn.Update(list); return(Json(new { data = "Send", success = "Update Sucessfull" })); } } }