public ActionResult Items_remove(int id) { var res = false; var mng = new ImpManager(); //проверка на дочерние var itemchild = mng.GetItemLogs(id); if (itemchild.Count != 0) { return(Json(new { result = res, msg = "Сперва удалите/измените логи по действиям!" })); } var item = mng.GetItem(id); if (item != null) { mng.DeleteItem(item); res = true; } return(Json(new { result = res, msg = "Действие удалено !" })); }
//public ActionResult ItemLogs_getItems() //{ // var parameters = AjaxModel.GetParameters(HttpContext); // var mng = new ImpManager(); // DateTime createdMin = (DateTime) System.Data.SqlTypes.SqlDateTime.MinValue; // DateTime createdMax = (DateTime) System.Data.SqlTypes.SqlDateTime.MaxValue; // var isImport = -1; // var withBackup = -1; // var itemID = 0; // //---------------обработка фильтров // if (parameters.filter != null && parameters.filter.Count > 0) // { // if (parameters.filter.ContainsKey("created") && parameters.filter["created"] != null) // { // var dates = parameters.filter["created"].ToString().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); // if (dates.Length > 0) // { // createdMin = RDL.Convert.StrToDateTime(dates[0].Trim(), (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue); // } // if (dates.Length > 1) // { // createdMax = RDL.Convert.StrToDateTime(dates[1].Trim(), (DateTime)System.Data.SqlTypes.SqlDateTime.MaxValue); // } // } // if (parameters.filter.ContainsKey("isImport") && parameters.filter["isImport"] != null) // { // isImport = RDL.Convert.StrToInt(parameters.filter["isImport"].ToString(), 0); // } // if (parameters.filter.ContainsKey("withBackup") && parameters.filter["withBackup"] != null) // { // withBackup = RDL.Convert.StrToInt(parameters.filter["withBackup"].ToString(), 0); // } // if (parameters.filter.ContainsKey("itemId") && parameters.filter["itemId"] != null) // { // itemID = RDL.Convert.StrToInt(parameters.filter["itemId"].ToString(), 0); // if (itemID == -1) itemID = 0; // } // } // var sorts = parameters.sort.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); // var directions = parameters.direction.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); // var sort1 = sorts.Length > 0 ? sorts[0] : ""; // var direction1 = directions.Length > 0 ? directions[0] : ""; // var rep = new ImpRepository(); // var p = new DynamicParameters(); // p.Add("isImport",isImport); // p.Add("withBackup",withBackup); // p.Add("itemID",itemID); // p.Add("createdMin",createdMin); // p.Add("createdMax",createdMax); // p.Add("sort1", sort1); // p.Add("direction1", direction1); // p.Add("page", parameters.page); // p.Add("pageSize", parameters.pageSize); // p.Add("total", dbType: DbType.Int32, direction: ParameterDirection.Output); // var items = rep.GetSQLData<dynamic>("GetItemLogs", p, CommandType.StoredProcedure); // var total = p.Get<int>("total"); // var json = JsonConvert.SerializeObject(new // { // items, // total = total // }); // return Content(json, "application/json"); //} public ActionResult ItemLogs_getItems() { var parameters = AjaxModel.GetParameters(HttpContext); var mng = new ImpManager(); var items = mng.GetItemLogs().AsQueryable(); //---------------обработка фильтров if (parameters.filter != null && parameters.filter.Count > 0) { DateTime createdMin = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue; DateTime createdMax = (DateTime)System.Data.SqlTypes.SqlDateTime.MaxValue; if (parameters.filter.ContainsKey("created") && parameters.filter["created"] != null) { var dates = parameters.filter["created"].ToString().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (dates.Length > 0) { createdMin = RDL.Convert.StrToDateTime(dates[0].Trim(), (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue); } if (dates.Length > 1) { createdMax = RDL.Convert.StrToDateTime(dates[1].Trim(), (DateTime)System.Data.SqlTypes.SqlDateTime.MaxValue); } items = items.Where(x => x.created >= createdMin && x.created <= createdMax).AsQueryable(); } if (parameters.filter.ContainsKey("isImport") && parameters.filter["isImport"] != null) { var isImport = RDL.Convert.StrToInt(parameters.filter["isImport"].ToString(), 0); if (isImport == 1) { items = items.Where(x => x.isImport == true).AsQueryable(); } if (isImport == 0) { items = items.Where(x => x.isImport == false).AsQueryable(); } } if (parameters.filter.ContainsKey("withBackup") && parameters.filter["withBackup"] != null) { var withBackup = RDL.Convert.StrToInt(parameters.filter["withBackup"].ToString(), 0); if (withBackup == 0) { items = items.Where(x => x.withBackup == false).AsQueryable(); } if (withBackup == 1) { items = items.Where(x => x.withBackup == true).AsQueryable(); } } if (parameters.filter.ContainsKey("itemId") && parameters.filter["itemId"] != null) { var itemID = RDL.Convert.StrToInt(parameters.filter["itemId"].ToString(), 0); if (itemID != -1) { items = items.Where(x => x.itemID == itemID).AsQueryable(); } } } var sorts = parameters.sort.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); var directions = parameters.direction.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); var sort1 = sorts.Length > 0 ? sorts[0] : ""; var direction1 = directions.Length > 0 ? directions[0] : ""; switch (sort1) { case "itemID": if (direction1 == "up") { items = items.OrderBy(x => x.itemID); } else { items = items.OrderByDescending(x => x.itemID); } break; case "created": if (direction1 == "up") { items = items.OrderBy(x => x.created); } else { items = items.OrderByDescending(x => x.created); } break; case "createdBy": if (direction1 == "up") { items = items.OrderBy(x => x.createdBy); } else { items = items.OrderByDescending(x => x.createdBy); } break; case "errors": if (direction1 == "up") { items = items.OrderBy(x => x.errors); } else { items = items.OrderByDescending(x => x.errors); } break; case "info": if (direction1 == "up") { items = items.OrderBy(x => x.info); } else { items = items.OrderByDescending(x => x.info); } break; case "durationSec": if (direction1 == "up") { items = items.OrderBy(x => x.durationSec); } else { items = items.OrderByDescending(x => x.durationSec); } break; case "withBackup": if (direction1 == "up") { items = items.OrderBy(x => x.withBackup); } else { items = items.OrderByDescending(x => x.withBackup); } break; case "isImport": if (direction1 == "up") { items = items.OrderBy(x => x.isImport); } else { items = items.OrderByDescending(x => x.isImport); } break; default: if (direction1 == "up") { items = items.OrderBy(x => x.created); } else { items = items.OrderByDescending(x => x.created); } break; } var total = items.Count(); var res = items.Skip(parameters.pageSize * (parameters.page - 1)).Take(parameters.pageSize).ToList(); return(Json(new { items = res.Select(x => new { x.id, itemName = x.imp_items.name, x.itemID, created = x.created.GetValueOrDefault().ToString("dd.MM.yyyy"), x.createdBy, x.errors, x.info, x.durationSec, withBackup = (x.withBackup == true) ? "Да" : "Нет", isImport = (x.isImport == true) ? "Да" : "Нет" }), total = items.Count() }, JsonRequestBehavior.AllowGet)); }