2017-11-29 21:32:55 +08:00
|
|
|
|
using System;
|
2021-07-22 19:33:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-17 23:04:04 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2017-11-29 21:32:55 +08:00
|
|
|
|
using Infrastructure;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-11-30 17:47:41 +08:00
|
|
|
|
using OpenAuth.App;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using OpenAuth.App.Interface;
|
2017-11-29 21:32:55 +08:00
|
|
|
|
using OpenAuth.App.Request;
|
|
|
|
|
using OpenAuth.App.Response;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class CategoriesController : BaseController
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
private readonly CategoryApp _app;
|
|
|
|
|
private CategoryTypeApp _categoryTypeApp;
|
|
|
|
|
public CategoriesController(IAuth authUtil, CategoryApp app, CategoryTypeApp categoryTypeApp) : base(authUtil)
|
|
|
|
|
{
|
|
|
|
|
_app = app;
|
|
|
|
|
_categoryTypeApp = categoryTypeApp;
|
|
|
|
|
}
|
2017-11-29 21:32:55 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /UserManager/
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 23:04:04 +08:00
|
|
|
|
public async Task<string> All([FromQuery]QueryCategoryListReq request)
|
2017-11-29 21:32:55 +08:00
|
|
|
|
{
|
|
|
|
|
TableData data = new TableData();
|
2020-12-17 23:04:04 +08:00
|
|
|
|
data = await _app.Load(request);
|
2017-11-29 21:32:55 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(data);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
[HttpPost]
|
2017-11-29 21:32:55 +08:00
|
|
|
|
public string Delete(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
Response resp = new Response();
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Delete(ids);
|
2017-11-29 21:32:55 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Add(AddOrUpdateCategoryReq obj)
|
2017-11-29 21:32:55 +08:00
|
|
|
|
{
|
|
|
|
|
Response resp = new Response();
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Add(obj);
|
2017-11-29 21:32:55 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Update(AddOrUpdateCategoryReq obj)
|
2017-11-29 21:32:55 +08:00
|
|
|
|
{
|
|
|
|
|
Response resp = new Response();
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Update(obj);
|
2017-11-29 21:32:55 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 得到所有的字典定义
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2017-11-29 21:32:55 +08:00
|
|
|
|
public string AllTypes()
|
|
|
|
|
{
|
2021-07-22 19:33:55 +08:00
|
|
|
|
var resp = new Response<List<CategoryTypeResp>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
resp.Result = _categoryTypeApp.AllTypes().MapToList<CategoryTypeResp>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
|
2017-11-29 21:32:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|