public JsonResult GetGroupOption() { var options = new List <Option> { new Option { DisplayText = "Chọn nhóm", Value = 0 } }; List <Admin_Group> groups = Admin_Group.Query("Where Id!=1 And Status=1").ToList(); if (groups.Any()) { options.AddRange(groups.Select(c => new Option { DisplayText = Convert.ToString(c.Name), Value = Convert.ToInt32(c.Id) }).ToList()); } return(Json(new { Result = 1, Records = options, options.Count }, JsonRequestBehavior.AllowGet)); }
public JsonResult Create_Group(Admin_Group obj) { Admin_Group Acc = new Admin_Group(); try { Acc.Name = obj.Name; Acc.Description = obj.Description; Acc.CreatedDate = DateTime.Now; Acc.Status = 1; Acc.Save(); } catch (Exception ex) { return(Json(0)); } return(Json(new { Result = 1, Records = Acc })); }
public JsonResult Delete_Group(Admin_Group obj) { List <Admin_Group> Acc = Admin_Group.Query("Where Id=@0", obj.Id).ToList(); try { if (Acc.Count > 0) { Acc.FirstOrDefault().Status = obj.Status; Acc.FirstOrDefault().Save(); } } catch { return(Json(0)); } return(Json(new { Result = 1, Records = Acc })); }
public JsonResult Update_Group(Admin_Group obj) { List <Admin_Group> Acc = Admin_Group.Query("Where Id=@0", obj.Id).ToList(); try { if (Acc.Any()) { Acc.FirstOrDefault().Name = obj.Name; Acc.FirstOrDefault().Description = obj.Description; Acc.SingleOrDefault().UpdatedDate = DateTime.Now; Acc.FirstOrDefault().Save(); } } catch (Exception ex) { return(Json(0)); } return(Json(new { Result = 1, Records = Acc })); }
public JsonResult Get_Group_List(DataModel obj) { string order = string.Empty; int totalRecords = int.MinValue; if (obj._od != null) { order = " Order By " + obj._od.FirstOrDefault().Key + " " + obj._od.FirstOrDefault().Value; } List <Admin_Group> AccList_source = new List <Admin_Group>(); List <Group_Config> AccList = new List <Group_Config>(); string msg = string.Empty; try { if (obj._c != null) { string querystring = ""; foreach (var k in obj._c) { switch (k.Key) { case "Name": querystring += k.Value.ToString(); break; default: querystring += k.Key + "=" + k.Value.ToString(); break; } if (!k.Equals(obj._c.Last())) { querystring += " AND "; } } AccList_source = Admin_Group.Query("Where " + querystring + order + "").ToList(); } else { AccList_source = Admin_Group.Query("" + order + "").ToList(); } // Map du lieu sang Model khac var config = new MapperConfiguration(cfg => { cfg.CreateMap <Admin_Group, Group_Config>(); }); IMapper mapper = config.CreateMapper(); AccList = mapper.Map <List <Admin_Group>, List <Group_Config> >(AccList_source); int pSize = obj._lm; totalRecords = AccList.Count(); if (totalRecords > 1) { AccList = AccList.Skip(obj._os).Take(pSize).ToList(); } } catch (Exception ex) { msg = ex.ToString(); } return(Json(new { Result = 1, TotalRecordCount = totalRecords, Records = AccList, Message = msg }, JsonRequestBehavior.AllowGet)); }