public int SaveBindingData(Base_DataBindViewModel dbModel) { var bdBindBll = new Base_DataBindBLL(); List <Base_DataBind> dbList = new List <Base_DataBind>(); if (dbModel.GenreId.Count() > 0) { foreach (string i in dbModel.GenreId) { var mdl = new Base_DataBind { GenreId = i, GradeId = dbModel.GradeId, PeriodId = dbModel.PeriodId, SchoolId = dbModel.SchoolId, SubjectId = dbModel.SubjectId }; //check if data exists string whr = bdBindBll.ArrayToWhere(mdl); bool exist = bdBindBll.GetBindingId("1=1 " + whr) != null; if (!exist) //not exists { dbList.Add(mdl); } } if (dbList.Count > 0) { return(SaveBindingModels(dbList)); } } return(0); }
/// <summary> /// get binded id that will be deleted. /// </summary> /// <param name="mdl"></param> /// <returns></returns> private int[] GetBindId(Base_DataBindViewModel mdl) { List <int> result = new List <int>(); if (mdl.GenreId.Count == 0) { return(null); } var bind = new Base_DataBind(); var bindBLL = new Base_DataBindBLL(); foreach (var i in mdl.GenreId) { bind = new Base_DataBind { GenreId = i, GradeId = mdl.GradeId, PeriodId = mdl.PeriodId, SchoolId = mdl.SchoolId, SubjectId = mdl.SubjectId }; string whr = bindBLL.ArrayToWhere(bind); var id = bindBLL.GetBindingId("1=1 " + whr); if (id != null) { result.Add(int.Parse(id)); } } return(result.ToArray()); }
/// <summary> /// /// </summary> /// <param name="upperIdList"></param> /// <returns></returns> public string ArrayToWhere(Base_DataBind model) { string whr = string.Empty; var props = model.GetType().GetProperties(); foreach (var property in props) { var prpName = property.Name; var prpVal = property.GetValue(model); if (prpName != "Id" && prpName != "SchoolId" && prpVal != null) { switch (prpName) { case nameof(model.PeriodId): whr += $" and periodid='{model.PeriodId}' "; break; case nameof(model.GradeId): whr += $" and gradeId='{model.GradeId}' "; break; case nameof(model.SubjectId): whr += $" and subjectId='{model.SubjectId}' "; break; case nameof(model.GenreId): whr += $" and genreid='{model.GenreId}' "; break; } } } return(whr); }
private Base_DataBind ArrayToModel(string[] listId) { var model = new Base_DataBind(); if (listId != null && listId.Count() > 0) { foreach (var item in listId) { var idarr = item.Split('_'); if (idarr.Length == 2) { switch (idarr[0]) { case "xd": model.PeriodId = idarr[1]; break; case "xk": model.SubjectId = idarr[1]; break; case "nj": model.GradeId = idarr[1]; break; case "lb": model.GenreId = idarr[1]; break; } } } } return(model); }
/// <summary> /// query lessons by clicked 'a'. /// </summary> /// <param name="bindId"></param> /// <param name="pg"></param> /// <param name="ttl"></param> /// <param name="pgsz"></param> /// <returns></returns> public BindingLessonViewModel QueryPagedLessons(Base_DataBind datas, int pg, int pgsz) { Base_DataBindBLL bindBll = new Base_DataBindBLL(); string whr = " schoolid=1"; int ttl = 0; whr += bindBll.ArrayToWhere(datas); var mdl = new BindingLessonViewModel() { TrainBaseLessons = _lessonBLL.Query(whr, pg, out ttl, 10), Pager = Common.Utility.HtmlPager(10, pg, ttl, 5) }; return(mdl); }
public string DataBindToWhere(Base_DataBind mdl) { string whr = " schoolid=1"; if (mdl.GradeId != null && mdl.PeriodId != null && mdl.SubjectId != null) { whr += " and periodid='" + mdl.PeriodId + "'"; whr += " and gradeid='" + mdl.GradeId + "'"; whr += " and subjectid='" + mdl.SubjectId + "'"; whr += " and genreId='" + mdl.GenreId + "'"; } return(whr); }
public ActionResult Index(Base_DataBind model, int pg = 1) { if (model == null) { return(Json(new { err = "params null" }, JsonRequestBehavior.AllowGet)); } if (model.GenreId == null || model.GradeId == null || model.PeriodId == null || model.SubjectId == null) { return(PartialView()); } string whr = DataBindToWhere(model); int i; var mdl = _lessonBLL.Query(whr, pg, out i, 10); ViewData["pager"] = Common.Utility.HtmlPager(10, pg, i, 5); return(PartialView("lessonTable", mdl)); }
public ActionResult AddStart(Base_DataBind model, string info) { string whr = DataBindToWhere(model); int i = _lessonSv.GetBindId(whr); if (i == -1) { throw new Exception("Bind id not found"); } var mdl = new TrainLessonViewModel { IsEdit = false, TrainBaseLesson = new TrainBaseLesson() { Id = Guid.NewGuid().ToString("n"), Base_DataBindId = i }, LessonInfo = info }; return(PartialView("edit", mdl)); }
/// <summary> /// get trainbaselesson list by binded datas --ajax /// </summary> /// <param name="bindId"></param> /// <param name="pg"></param> /// <returns></returns> public ActionResult LessonList(Base_DataBind datas, int pg = 1) { var mdl = trainBaseLessonSvc.QueryPagedLessons(datas, pg, 10); return(PartialView(mdl)); }