using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.Models.CodeCtnSet; using DSWeb.MvcShipping.DAL.MsCodeCtnSet; using DSWeb.MvcShipping.Helper; using HcUtility.Comm; using HcUtility.Core; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsCodeCtnSetController : Controller { /// /// 视图 /// /// public ActionResult Index() { return View(); } /// /// 获取分页列表 /// /// /// /// /// /// public ContentResult GetList(int start, int limit, string condition, string sort) { var dataList = MsCodeCtnSetDAL.GetListByPage(condition, sort, start, start + limit); int recordCount = MsCodeCtnSetDAL.GetRecordCount(condition); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = recordCount, data = dataList.ToList() }); return new ContentResult { Content = json }; } /// /// 获取实例 /// /// /// /// public ContentResult GetData(string handle, string id) { var model = MsCodeCtnSetDAL.GetData(id); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = model }); return new ContentResult { Content = json }; } /// /// 批量删除 /// /// /// public ContentResult Delete(string data) { var datalist = JsonConvert.Deserialize>(data); var modb = new ModelObjectDB(); DBResult result = new DBDataSetResult(); var jsonRespose = new JsonResponse { Success = false, Message = "删除失败" }; foreach (var item in datalist) { result = modb.Delete(item); if (!result.Success)//有失败直接返回结果 return new ContentResult { Content = JsonConvert.Serialize(jsonRespose) }; } jsonRespose = new JsonResponse { Success = true, Message = "删除成功" }; return new ContentResult { Content = JsonConvert.Serialize(jsonRespose) }; } /// /// 批量保存 /// /// /// public ContentResult Save(string body) { var bodyList = JsonConvert.Deserialize>(body); foreach (var item in bodyList) { if (String.IsNullOrEmpty(item.CTNID)) { item.CTNID = Guid.NewGuid().ToString(); MsCodeCtnSetDAL.Add(item); } else MsCodeCtnSetDAL.Update(item); } var jsonRespose = new JsonResponse { Success = true, Message = "保存成功" }; return new ContentResult { Content = JsonConvert.Serialize(jsonRespose) }; } } }