156 lines
4.9 KiB
C#
156 lines
4.9 KiB
C#
using Common.Models.UnqTables;
|
|
using Common.Utils;
|
|
using Server.MyClass.Views;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
|
|
namespace Server.Controllers.MemberManagement
|
|
{
|
|
|
|
public class GroupingController : DefaultController
|
|
{
|
|
/// <summary>
|
|
/// 查询用户分组
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult GetUserGroups()
|
|
{
|
|
var Keyword = GetString("Keyword");
|
|
var PageIndex = GetInt("PageIndex", true);
|
|
var PageSize = GetInt("PageSize", true);
|
|
if (PageSize > 100) PageSize = 100;
|
|
|
|
var tNumber = 0;
|
|
|
|
var exp = Expressionable.Create<UserGroup>();
|
|
|
|
if (!string.IsNullOrEmpty(Keyword))
|
|
exp.And(f => f.Name.Contains(Keyword));
|
|
|
|
var DataList = Db.Queryable<UserGroup>()
|
|
.LeftJoin<ConfigData>((f, g) => f.ReplyId == g.Id)
|
|
.Where(exp.ToExpression())
|
|
.Select((f, g) => new UserGroupView() {
|
|
AotuSort = f.AotuSort,
|
|
ConfigName = g.Name,
|
|
Describe = f.Describe,
|
|
Id = f.Id,
|
|
MaximumOrder = f.MaximumOrder,
|
|
Name = f.Name,
|
|
ReplyId = f.ReplyId
|
|
})
|
|
.ToPageList(PageIndex, PageSize, ref tNumber);
|
|
|
|
var res = new PageResult<UserGroupView>(DataList, tNumber, PageSize, PageIndex);
|
|
|
|
return PutData(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑用户分组
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult UpdUserGroup()
|
|
{
|
|
var Id = GetInt("Id", true);
|
|
var Name = GetString("Name",true);
|
|
var Describe = GetString("Describe");
|
|
var AotuSort = GetBoolean("AotuSort");
|
|
var MaximumOrder = GetInt("MinOrder");
|
|
var ReplyId = GetInt("ReplyId");
|
|
|
|
|
|
var user = Db.Queryable<UserGroup>().Single(f => f.Id == Id);
|
|
|
|
if (user == null)
|
|
{
|
|
return PutData("编辑失败,此用户组不存在或已被删除");
|
|
}
|
|
|
|
var cacheGroup = Db.Queryable<UserGroup>().Where(f=>f.Name == Name).First();
|
|
if (cacheGroup != null && cacheGroup.Id!=Id)
|
|
{
|
|
return PutData("此用户组名称已存在,请重新输入");
|
|
}
|
|
var temp = Db.Queryable<UserGroup>().Where(f => f.MaximumOrder == MaximumOrder).First();
|
|
if (temp != null && temp.Id!= Id) return PutData($"编辑失败,已存在订单要求为“{MaximumOrder}”的分组!");
|
|
user.Name = Name;
|
|
user.Describe = Describe;
|
|
user.AotuSort = AotuSort;
|
|
user.MaximumOrder = MaximumOrder;
|
|
user.ReplyId = ReplyId;
|
|
|
|
Db.Updateable(user).ExecuteCommand();
|
|
return PutSuccess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增用户分组
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult AddUserGroup()
|
|
{
|
|
var Name = GetString("Name", true);
|
|
var Describe = GetString("Describe");
|
|
var AotuSort = GetBoolean("AotuSort");
|
|
var MaximumOrder = GetInt("MaximumOrder");
|
|
var ReplyId = GetInt("ReplyId");
|
|
var userGroup = Db.Queryable<UserGroup>().Where(f =>f.Name == Name).First();
|
|
|
|
if (userGroup != null)
|
|
{
|
|
return PutData("已存在此名称,请重新输入");
|
|
}
|
|
|
|
if (AotuSort)
|
|
{
|
|
var temp = Db.Queryable<UserGroup>().Where(f => f.MaximumOrder == MaximumOrder).First();
|
|
if (temp != null) return PutData($"添加失败,已存在订单要求为“{MaximumOrder}”的分组!");
|
|
}
|
|
Db.Queryable<UserGroup>();
|
|
|
|
userGroup = new UserGroup()
|
|
{
|
|
Name = Name,
|
|
Describe = Describe,
|
|
AotuSort = AotuSort,
|
|
MaximumOrder = MaximumOrder,
|
|
ReplyId = ReplyId
|
|
};
|
|
|
|
Db.Insertable(userGroup).ExecuteCommand();
|
|
return PutSuccess;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除用户分组
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult DelUserGroup()
|
|
{
|
|
var Id = GetInt("Id", true);
|
|
|
|
var user = Db.Queryable<UserGroup>().Single(f => f.Id == Id);
|
|
|
|
if (user == null)
|
|
{
|
|
return PutData("删除失败,此用户组不存在或已被删除");
|
|
}
|
|
|
|
Db.Deleteable(user).ExecuteCommand();
|
|
|
|
return PutSuccess;
|
|
}
|
|
}
|
|
}
|