You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Controllers/MsCodeCtnSetController.cs

95 lines
3.5 KiB
C#

2 years ago
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
{
/// <summary>
/// 视图
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
return View();
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="condition"></param>
/// <param name="sort"></param>
/// <returns></returns>
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 };
}
/// <summary>
/// 获取实例
/// </summary>
/// <param name="handle"></param>
/// <param name="id"></param>
/// <returns></returns>
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 };
}
/// <summary>
/// 批量删除
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public ContentResult Delete(string data)
{
var datalist = JsonConvert.Deserialize<List<CodeCtnSet>>(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) };
}
/// <summary>
/// 批量保存
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
public ContentResult Save(string body)
{
var bodyList = JsonConvert.Deserialize<List<CodeCtnSet>>(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) };
}
}
}