OpenAuth.Net/OpenAuth.Mvc/Controllers/OrgManagerController.cs

110 lines
2.8 KiB
C#
Raw Normal View History

using Infrastructure;
2015-10-26 21:58:12 +08:00
using OpenAuth.App;
2015-10-29 23:51:10 +08:00
using OpenAuth.Domain;
2015-11-05 23:27:08 +08:00
using OpenAuth.Mvc.Models;
2015-11-06 00:27:08 +08:00
using System;
using System.Web.Mvc;
2015-10-26 21:58:12 +08:00
namespace OpenAuth.Mvc.Controllers
{
2015-11-06 00:27:08 +08:00
public class OrgManagerController : BaseController
{
private OrgManagerApp _orgApp;
2015-10-26 21:58:12 +08:00
2015-11-06 00:27:08 +08:00
public OrgManagerController()
{
_orgApp = AutofacExt.GetFromFac<OrgManagerApp>();
2015-11-06 00:27:08 +08:00
}
//
// GET: /OrgManager/
public ActionResult Index()
{
return View();
}
2015-10-26 21:58:12 +08:00
2015-11-05 23:27:08 +08:00
/// <summary>
/// 选择上级机构页面
/// </summary>
/// <returns>ActionResult.</returns>
2015-11-06 00:27:08 +08:00
public ActionResult LookupParent()
{
return View();
}
2015-10-26 21:58:12 +08:00
2015-11-06 00:27:08 +08:00
public ActionResult AddOrg()
{
return View();
}
2015-11-05 23:27:08 +08:00
//添加组织提交
[HttpPost]
2015-11-06 00:27:08 +08:00
public string AddOrg(Org org)
2015-11-05 23:27:08 +08:00
{
try
{
2015-11-24 15:49:00 +08:00
_orgApp.AddOrUpdate(org);
2015-11-05 23:27:08 +08:00
}
catch (Exception ex)
{
2015-11-08 23:19:04 +08:00
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
2015-11-05 23:27:08 +08:00
}
2015-11-08 23:19:04 +08:00
return JsonHelper.Instance.Serialize(BjuiResponse);
2015-11-05 23:27:08 +08:00
}
2015-11-06 00:27:08 +08:00
public string EditOrg(string json)
{
try
{
var org = JsonHelper.Instance.Deserialize<Org>(json);
2015-11-24 15:49:00 +08:00
_orgApp.AddOrUpdate(org);
2015-11-06 00:27:08 +08:00
}
catch (Exception ex)
{
2015-11-08 23:19:04 +08:00
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
2015-11-06 00:27:08 +08:00
}
2015-11-08 23:19:04 +08:00
return JsonHelper.Instance.Serialize(BjuiResponse);
2015-11-06 00:27:08 +08:00
}
2015-11-05 23:27:08 +08:00
2015-11-06 00:27:08 +08:00
public string LoadOrg()
{
2015-11-13 21:33:53 +08:00
var orgs = _orgApp.GetAll();
//添加根节点
2015-11-13 21:33:53 +08:00
orgs.Add(new Org
{
Id = 0,
ParentId = -1,
2015-12-02 10:06:30 +08:00
Name = "根结点",
2015-11-13 21:33:53 +08:00
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(orgs);
2015-11-06 00:27:08 +08:00
}
2015-10-28 22:49:59 +08:00
2015-11-06 00:27:08 +08:00
public string LoadChildren(int id)
{
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
}
2015-10-29 23:51:10 +08:00
2015-11-05 23:27:08 +08:00
/// <summary>
/// 删除指定ID的组织
/// <para>Id为逗号分开的字符串</para>
/// </summary>
/// <returns>System.String.</returns>
public string DelOrg(int Id)
2015-10-30 23:14:31 +08:00
{
2015-11-03 00:22:54 +08:00
try
2015-10-30 23:14:31 +08:00
{
_orgApp.DelOrg(Id);
2015-10-30 23:14:31 +08:00
}
2015-11-03 00:22:54 +08:00
catch (Exception e)
{
2015-11-08 23:19:04 +08:00
BjuiResponse.statusCode = "300";
BjuiResponse.message = e.Message;
2015-11-03 00:22:54 +08:00
}
2015-11-08 23:19:04 +08:00
return JsonHelper.Instance.Serialize(BjuiResponse);
2015-10-30 23:14:31 +08:00
}
2015-11-06 00:27:08 +08:00
}
2015-10-26 21:58:12 +08:00
}