<%@ WebHandler Language="C#" Class="GwOpGroupHandler" %>
|
|
using System;
|
using System.Web;
|
using Model;
|
using Common;
|
using Dao;
|
using System.Linq;
|
|
public class GwOpGroupHandler : PageHandler<Model.SysUser>
|
{
|
private GwOpGroupDao _Dao = new GwOpGroupDao();
|
|
public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
|
{
|
string action = context.GetString("action");
|
|
switch (action)
|
{
|
case "delete":
|
return Delete(context);
|
|
case "save":
|
return Save(context);
|
|
case "getGroup":
|
return GetGroup(context);
|
|
default:
|
throw new Exception("Invalid Action=" + action);
|
}
|
}
|
|
private JsonPageResult GetGroup(PageContext<SysUser> context)
|
{
|
int groupID = context.GetInt("groupid");
|
|
return new JsonPageResult(true, _Dao.GetGroup(groupID));
|
}
|
|
private JsonPageResult Delete(PageContext<SysUser> context)
|
{
|
int groupID = context.GetInt("groupID");
|
|
_Dao.Delete(groupID);
|
|
return new JsonPageResult(true, "通道组删除成功!");
|
}
|
|
private JsonPageResult Save(PageContext<SysUser> context)
|
{
|
int groupID = context.GetInt("groupID");
|
string groupName = context.GetString("groupName");
|
string groupData = context.GetString("groupData");
|
|
if (string.IsNullOrEmpty(groupName))
|
{
|
throw new ArgumentException("通道组名称不能为空!");
|
}
|
|
var array = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(groupData) ;
|
|
if (string.IsNullOrEmpty(groupData) || array == null)
|
{
|
throw new ArgumentException("通道数据异常,请重新设置!");
|
}
|
|
foreach (var a in array)
|
{
|
if (a.Value<int>("weight") < 0 || a.Value<int>("weight") > 10)
|
{
|
throw new ArgumentException("每个通道权重范围必须在0-10之间!");
|
}
|
}
|
|
if (array.Sum(c => c.Value<int>("weight")) == 0)
|
{
|
throw new ArgumentException("通道权重不能全部为0!");
|
}
|
|
if (_Dao.IsGroupNameExists(groupID, groupName))
|
{
|
throw new ArgumentException("通道组名称重复,请重新输入!");
|
}
|
|
if (groupID > 0)
|
{
|
_Dao.Update(groupID, groupName, groupData);
|
}
|
else
|
{
|
_Dao.Add(groupName, groupData);
|
}
|
|
|
return new JsonPageResult(true, "通道组保存成功!");
|
}
|
}
|