123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using MiniWebApi.Handler;
- using MiniWebApi.Network;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Text;
- using Vinno.vCloud.Disk.Database;
- using Vinno.vCloud.Disk.Database.Dto;
- using Vinno.vCloud.Disk.UFile;
- using Vinno.vCloud.Common.Storage.ObjectStorageInfo.Authorization;
- using System.Text.RegularExpressions;
- namespace Vinno.vCloud.Disk.Controllers
- {
- [WebApiHandler("User")]
- internal class UserController : BaseHandler
- {
- /// <summary>
- /// 获取用户列表
- /// </summary>
- /// <param name="context"></param>
- [Get]
- public void GetUserList(WebApiHttpContext context)
- {
- var page = context.GetParam("page").ToInt();
- var limit = context.GetParam("limit").ToInt();
- var data = SqlExecute.DB.Table<User>().OrderByDescending(f => f.Id);
- var dtos = data.ToList();
- var result = new
- {
- code = 0,
- msg = "",
- count = dtos.Count(),
- data = dtos.Skip((page - 1) * limit).Take(limit)
- };
- context.Response.Json(result, true);
- }
- /// <summary>
- /// 根据用户名获取用户
- /// </summary>
- /// <param name="context"></param>
- [Get]
- public void GetUserByName(WebApiHttpContext context)
- {
- var name = context.GetParam("name");
- var data = SqlExecute.DB.Query(SqlExecute.DB.GetMapping<User>(), "select * from User where LOWER(Name)=?", WebUtility.UrlDecode(name).ToLower())?.FirstOrDefault();
- context.Response.Json(data, true);
- }
- /// <summary>
- /// 删除用户
- /// </summary>
- /// <param name="context"></param>
- [Post]
- public void DeleteUser(WebApiHttpContext context)
- {
- var param = context.GetParams();
- var ids = param.GetArrayValue("ids");
- var isSuccess = SqlExecute.DB.Execute($"delete from User where Id in ({string.Join(',', ids)})") >0;
- context.Response.Json(new
- {
- Success = isSuccess,
- Msg = string.Empty
- }, true);
- }
- /// <summary>
- /// 添加用户
- /// </summary>
- /// <param name="context"></param>
- [Post]
- public void AddUser(WebApiHttpContext context)
- {
- var param = context.GetParams();
- var userName = param.GetStringValue("userName").Trim();
- var role = param.GetStringValue("role").ToInt();
- if (string.IsNullOrWhiteSpace(userName))
- {
- //这里需要加上失败返回类型
- return;
- }
- User user = new User();
- user.Name = userName;
- user.Role = role;
- var data = SqlExecute.DB.Query(SqlExecute.DB.GetMapping<User>(),"select * from User where LOWER(Name)=?", WebUtility.UrlDecode(userName).ToLower());
- if (data.Count <= 0)
- {
- var isSuccess = SqlExecute.DB.Insert(user) > 0;
- context.Response.Json(new
- {
- Success = isSuccess,
- Msg = string.Empty
- }, true);
- }
- else
- {
- context.Response.Json(new
- {
- Success = false,
- Msg = "User already exist!"
- }, true);
- }
- }
- /// <summary>
- /// 编辑用户
- /// </summary>
- /// <param name="context"></param>
- [Post]
- public void EditUser(WebApiHttpContext context)
- {
- var param = context.GetParams();
- var id = param.GetStringValue("id").ToInt();
- var name = param.GetStringValue("userName");
- var role = param.GetStringValue("role").ToInt();
- if (string.IsNullOrWhiteSpace(name))
- {
- //这里需要加上失败返回类型
- return;
- }
- User user = new User();
- user.Id = id;
- user.Name = name;
- user.Role = role;
- var isSuccess = SqlExecute.DB.Update(user) > 0;
- context.Response.Json(new
- {
- Success = isSuccess,
- Msg = string.Empty
- }, true);
- }
- }
- }
|