TRMS
@model TRMS.Model.Member.User
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="DIV_MAIN_CONTENT">
    @using (Html.BeginForm("Edit", "UserInforChange", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        <fieldset style="width:680px; border:1px; margin-top:0; margin-left:auto; margin-right:auto;">
            @Html.HiddenFor(model => model.ID)
            <h2 style="margin-left:auto; margin-right:auto; margin-top:auto;">Edit</h2>
            <div style="border:1px; margin-top:0; margin-left:auto; margin-right:auto;"  border=" 0">
                <div>
                    <div class="div-input-group-table" style="float:left;width:74%;">
                        <div>
                            <div class="div-input-group-title">中文名:</div>
                            <div class="div-input-group-content" style="padding-left:10px;">@Html.DisplayFor(model => model.ChineseName)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">英文名:</div>
                            <div class="div-input-group-content" style="padding-left:10px;">@Html.DisplayFor(model => model.EnglishName)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">邮   箱:</div>
                            <div class="div-input-group-content" style="padding-left:10px;">@Html.DisplayFor(model => model.Email)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">创建时间:</div>
                            <div class="div-input-group-content" style="padding-left:10px;">@Html.DisplayFor(model => model.CreationTime)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">厂   区:</div>
                            <div class="div-input-group-content" style="padding-left:10px;">@Html.DisplayFor(model => model.SiteName)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">移动电话:</div>
                            <div class="div-input-group-content">@Html.EditorFor(model => model.MobilePhone)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">工作电话:</div>
                            <div class="div-input-group-content">@Html.EditorFor(model => model.WorkPhone)</div>
                        </div>
                        <div>
                            <div class="div-input-group-title">微信ID:</div>
                            <div class="div-input-group-content">@Html.EditorFor(model => model.WeChartID)</div>
</div>
</div>
                    <div style="padding:0 0 0 0;grid-row-span:1; float:left;height:280px;width:25%;margin-top:10px;">
                        @if (string.IsNullOrEmpty(Model.PhotoPath))
                        {
                            <div style="width:167px;height:259px;padding:0;border:1px solid #cdcdcd;border-left:0;" background="~/Image/none.jpg">
                                <p style="text-align:center;vertical-align:middle;line-height:259px;">你还没有上传图片</p>
                            </div>
                        }
                        else
                        {
<input type="image" style="width:167px;height:259px;padding:0;" src="@Url.Content(Model.PhotoPath)" alt="image">
                        }
                        <input type="file" id="f" style="width:167px;padding:0;" name="f" accept="image/*" value="用户头像" />
                    </div>
                </div>
                <div class="div-input-group-table" style="margin-top:0;float:left;">
                    <div>
                        <div class="div-input-group-title div-input-group-header">备   注:</div>
                    </div>
                    <div>
                        <div class="div-input-group-content" style="border-bottom:1px solid #cdcdcd;">@Html.DisplayFor(model => model.Remark)</div>
                    </div>
                </div>
            </div>
            <div style="padding-top:5px;padding-bottom:15px;">
                <input type="submit" value="Save"/>
            </div>
            <p>
                @Html.Raw(Server.HtmlDecode(Html.ValidationSummary(false).ToString()))
            </p>
        </fieldset>
    }
</div>
<style>
    .div-input-group-title{
        width:80px;
        border-bottom:0;
        
    }
    .div-input-group-content{
        border-bottom:0;
    }
</style>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing.Imaging;
using System.Drawing;
// POST: /UserInforChange/Edit/5
 [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(TRMS.Model.Member.User _user, HttpPostedFileBase f)
        {
            try
            {
                if (_user.ID == null || _user.ID.Length < 1)
                {
                    return View("Error");
                }
                TRMS.BLL.Member.IUser User_Infor = TRMS.BLL.FactoryManager.GetUserFac();
                TRMS.Model.Member.User new_user = User_Infor.Load(_user.ID);
                new_user.MobilePhone = _user.MobilePhone;
                new_user.WorkPhone = _user.WorkPhone;
                
                if (f != null)
                {
                   
                    Random random = new Random();
                    int num = random.Next(0, 10000);
                    if (f.ContentLength > 10485760)  //设置图片最大为10M( 1024 *1024 * 10 = 10485760)
                    {
                        ViewBag.fileupload = "图片大小不能超过10M";
                        return View("Edit", new_user);
                    }
                   
                    var fileName = System.IO.Path.GetExtension(f.FileName);//获取文件扩展名
                    var path = System.IO.Path.Combine(Server.MapPath("~/Image/"), _user.ID + num + fileName); //用用户名标记图片,以免图片文件名一样而覆盖
                    f.SaveAs(path);
                   
                    new_user.PhotoPath = System.IO.Path.Combine("~/Image/", _user.ID + num + fileName);
                }
                long LogID = 0;
                if (User_Infor.Update(new_user, new_user.ID, out  LogID))
                {
                    return RedirectToAction("Edit");
                }
                else
                {
                    return View(_user);
                }
            }
            catch 
            {
                return View();
            }
        }
 /// <summary>
        /// 个人报表
        /// </summary>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        [HttpGet]
        //public ActionResult GetReportByDay(DateTime StartTime, DateTime EndTime, string UserID)
        public ActionResult GetReportByDay(DateTime StartTime, DateTime EndTime, string SearchType)
        {
            IWorkRecord RecordItem = FactoryManager.GetWorkRecordFac();
            var RecordList = RecordItem.GetReportByUser(StartTime, EndTime, User.Identity.Name);
            Dictionary<string, double> DayWorkTime = new Dictionary<string, double>();
            Dictionary<string, double> RealDayWorkTime = new Dictionary<string, double>();
            ViewBag.SearchType = new List<SelectListItem>() 
            {
                 new SelectListItem (){Value ="BU",Text ="按BU统计"},
                 new SelectListItem(){Value ="Day",Text ="按天数统计"},
                 new SelectListItem(){Value = "Project",Text="按Project统计"}
            };
           
            if (RecordList.Count > 0)
            {
                while (StartTime.Date <= EndTime.Date)
                {
                    //计算每天的工作时间
                    var _record = RecordList.Where(r => r.StartTime <= StartTime.AddDays(1) && r.EndTime >= StartTime);
                    
                    if (_record.Count() > 0)
                    {
                        double _totalWorkTime = 0;
                        double _realWorkTime = 8;
                        foreach (var item in _record)
                        {
                            _totalWorkTime = _totalWorkTime + item.Duration;
                        }
                        if (_totalWorkTime >= 8)
                        {
                            RealDayWorkTime.Add(string.Format("{0}/{1}", StartTime.Month, StartTime.Day), _realWorkTime);
                        }
                        else
                        {
                            RealDayWorkTime.Add(StartTime.ToShortDateString(), _totalWorkTime);
                        }
                        DayWorkTime.Add(StartTime.ToString("MM/dd"), _totalWorkTime);
                    }
                    else
                    {
                        DayWorkTime.Add(StartTime.ToString("MM/dd"), 0);
                        RealDayWorkTime.Add(StartTime.ToString("MM/dd"), 0);
                    }
                    StartTime = StartTime.AddDays(1);
                } 
                if (SearchType == "Day")
                {
                    
                    if (DayWorkTime.Count() > 0)
                    {
                        List<string> lables = new List<string>();
                        List<double> data = new List<double>();
                        List<double> data2 = new List<double>();
                        foreach (var item in DayWorkTime)
                        {
                            lables.Add(item.Key);
                            data.Add(item.Value);
                        }
                        
                        foreach (var item in RealDayWorkTime)
                        {
                            data2.Add(item.Value);
                        }
                        return Json(new { Result = true, Lables = lables, data = data, data2 = data2 }, JsonRequestBehavior.AllowGet);
                    }
                }
                
                if (SearchType == "BU")
                {
                    Dictionary<string, int> BUList = new Dictionary<string, int>();
                    Dictionary<string, double> BUTime = new Dictionary<string, double>();
                    TRMS.BLL.Project.IProjectCode ProjectItem = TRMS.BLL.FactoryManager.GetProjectFac();
                    foreach (var item in RecordList)
                    {
                        ProjectCode projectCode = ProjectItem.Load(item.ProjectID);
                        if (projectCode != null)
                        {
                            if (!BUList.ContainsKey(projectCode.BU))
                            {
                                BUList.Add(projectCode.BU, projectCode.ID);
                            }
                        }
                    }
                    foreach (var item in BUList)
                    {
                        var _recordList = RecordList.Where(r => r.ProjectID == item.Value).ToList();
                        if (_recordList.Count > 0)
                        {
                            double totalTimeByBU = 0;
                            foreach (WorkRecord record in _recordList)
                            {
                                totalTimeByBU = totalTimeByBU + record.Duration;
                                           
                            }
                            BUTime.Add(item.Key, totalTimeByBU);
                        }
                        else
                        {
                            BUTime.Add(item.Key, 0);
                        }
                    }
                    if (BUTime.Count() > 0)
                    {
                        List<string> lables = new List<string>();
                        List<double> data = new List<double>();
                      
                        foreach (var item in BUTime)
                        {
                            lables.Add(item.Key);
                            data.Add(item.Value);                       
                        }
                        return Json(new { Result = true, Lables = lables, data = data }, JsonRequestBehavior.AllowGet);
                    }
                }
                
                
                if (SearchType == "Project")
                {
                    Dictionary<string, int> ProjectList = new Dictionary<string, int>();
                    Dictionary<string, double> ProjectTime = new Dictionary<string, double>();
                    TRMS.BLL.Project.IProjectCode ProjectItem = TRMS.BLL.FactoryManager.GetProjectFac();
                    foreach (var item in RecordList)
                    {
                        ProjectCode projectCode = ProjectItem.Load(item.ProjectID);
                        if (projectCode != null)
                        {
                            if (!ProjectList.ContainsKey(projectCode.ProjectNumber))
                            {
                                ProjectList.Add(projectCode.ProjectNumber, projectCode.ID);
                            }
                        }
                    }
                    foreach (var item in ProjectList)
                    {
                        var _recordList = RecordList.Where(r => r.ProjectID == item.Value).ToList();
                        if (_recordList.Count > 0)
                        {
                            double totalTimeProject = 0;
                            foreach (WorkRecord record in _recordList)
                            {
                                totalTimeProject = totalTimeProject + record.Duration;
                                
                            }
                            ProjectTime.Add(item.Key, totalTimeProject);
                        }
                        else
                        {
                            ProjectTime.Add(item.Key, 0);
                        }
                    }
                    if (ProjectTime.Count > 0)
                    {
                        List<string> lables = new List<string>();
                        List<double> data = new List<double>();
                        foreach (var item in ProjectTime)
                        {
                            lables.Add(item.Key);
                            data.Add(item.Value);
                        }
                        
                        return Json(new { Result = true, Lables = lables, data = data }, JsonRequestBehavior.AllowGet);
                    }
                }
            }
            
            return Json(new { Reuslt = false }, JsonRequestBehavior.AllowGet);
        }
#region 注册
 [OutputCache(NoStore = true, VaryByParam = "*", Duration = 0)]
        public JsonResult FistLogOnCheckUser(TRMS.User.Models.FistLogon firstlogonModel)
        {
            //1.检查用户是否已经存在本系统
            if (string.IsNullOrEmpty(firstlogonModel.UserName))
            {
                var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "用户名不能为空,请确认后重试", Value = "" };
                return Json(JsonData);
            }
            firstlogonModel.UserName = firstlogonModel.UserName.Trim().ToUpper();
            if (!App_Code.ValidatorCode.CheckValidateCode(firstlogonModel.VialdateCode))
            {
                var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "验证码输入不正确, 请确认后重试", Value = "" };
                return Json(JsonData);
            }
            TRMS.Model.Member.User UserItem = TRMS.BLL.FactoryManager.GetUserFac().Load(firstlogonModel.UserName);
            if (UserItem != null)
            {
                var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "用户已注册, 请直接登录", Value = "" };
                return Json(JsonData);
            }
            //2.检查用户工号是否存在HR系统 =》加载HR中的用户信息 得到 UserDataItem
            TRMS.User.Models.UserDetailData UserDataItem = new Models.UserDetailData();
            UserDataItem.UserID = firstlogonModel.UserName;
            HRUser hrUser = new HRUser();
            Dictionary<string, string> userInfoDic = new Dictionary<string, string>();
            if (hrUser.LogON())
            {
                if (hrUser.LoadUserInfo(firstlogonModel.UserName, out userInfoDic))
                {
                    char[] chararray = {' ',',','.'};
                    if (userInfoDic["Site"] == null)
                    {
                        UserDataItem.SiteName = "";  
                    }
                    else
                    {
                        UserDataItem.SiteName = userInfoDic["Site"].ToString().Trim().ToUpper();  //所在区域
                    }
                    if (userInfoDic["employeeName"] == null)
                    {
                        UserDataItem.ChineseName = "";
                    }
                    else
                    {
                        UserDataItem.ChineseName = userInfoDic["employeeName"].ToString().Trim();  //姓名
                    }
                    if (userInfoDic["OrganNo"] == null)
                    {
                        UserDataItem.Department = "";
                    }
                    else
                    {
                        UserDataItem.Department = userInfoDic["OrganNo"].ToString().Trim();  //部门代码
                    }
                    if (userInfoDic["AllManager"] == null)
                    {
                        UserDataItem.AllManager = "";
                    }
                    else
                    {
                        UserDataItem.AllManager = userInfoDic["AllManager"].ToString().Trim().ToUpper();   //所有直属主管
                    }
                    if (userInfoDic["NextLevelLeader"] == null)
                    {
                        UserDataItem.NextLevelLeader = "";
                    }
                    else
                    {
                        UserDataItem.NextLevelLeader = userInfoDic["NextLevelLeader"].ToString().Trim().ToUpper();  //上一级主管
                    }                  
                    if (userInfoDic["Email"] == null)
                    {
                        UserDataItem.Email = "";                        
                    }
                    else
                    {
                        UserDataItem.Email = userInfoDic["Email"].ToString().ToLower().Trim(chararray);  //Email
                    }
                    if (userInfoDic["Ext"] == null)
                    {
                        UserDataItem.WorkPhone = "";
                    }
                    else
                    {
                        UserDataItem.WorkPhone = userInfoDic["Ext"].ToString().Trim();  //分机
                    }
                    if (userInfoDic["Phone"] == null)
                    {
                        UserDataItem.MobilePhone = "";
                    }
                    else
                    {
                        UserDataItem.MobilePhone = userInfoDic["Phone"].ToString().Trim();  //手机
                    }
                    
                    var CacheKey = Guid.NewGuid().ToString("N");
                    
                    BLL.TRMSCache.Instance.SetCache(CacheKey, UserDataItem, TimeSpan.FromMinutes(15));             //加入缓存
                    var JsonData = new TRMS.Model.ActionResult { Result = true, Value = CacheKey };
                    return Json(JsonData);
                }
                else
                {
                    var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "HR系统中没有该用户的信息, 请确认后重试", Value = "" };
                    return Json(JsonData);
                }
            }
            else
            {
                var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "与HR系统连接出现错误, 请确认后重试", Value = "" };
                return Json(JsonData);
            }
        }
        public ActionResult Register(string id)
        {            
            Models.UserDetailData UserDataItem = new Models.UserDetailData();
            if (TRMS.BLL.TRMSCache.Instance.GetCache<Models.UserDetailData>(id, out UserDataItem))
            {
                return View(UserDataItem);
            }
            return View();  //未能获取缓存
        }
        [HttpPost]
        public ActionResult Register(Models.UserDetailData userdataModel)
        {
            if (string.IsNullOrEmpty(userdataModel.UserID))   //工号
            {
                ViewBag.returnStr = "用户工号不能为空, 请确认后重试";
                return View();
            }
            else
            {
                userdataModel.UserID = userdataModel.UserID.Trim().ToUpper();
            }
            if (string.IsNullOrEmpty(userdataModel.WorkPhone))   //分机
            {
                ViewBag.returnStr = "用户分机不能为空, 请确认后重试";
                return View();
            }
            else
            {
                userdataModel.WorkPhone = userdataModel.WorkPhone.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.SiteName))   //厂区
            {
                userdataModel.SiteName = "";
            }
            else
            {
                userdataModel.SiteName = userdataModel.SiteName.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.Password))        //密码
            {
                ViewBag.returnStr = "用户密码不能为空, 请确认后重试";
                return View();
            }
            else
            {
                userdataModel.Password = userdataModel.Password.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.MobilePhone))   //手机
            {
                ViewBag.returnStr = "用户手机不能为空, 请确认后重试";
                return View();
            }
            else
            {
                userdataModel.MobilePhone = userdataModel.MobilePhone.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.EnglishName))     //英文名
            {
                userdataModel.EnglishName = "";
            }
            else
            {
                userdataModel.EnglishName = userdataModel.EnglishName.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.NextLevelLeader))   //上一级主管
            {
                userdataModel.NextLevelLeader = "";
            }
            else
            {
                userdataModel.NextLevelLeader = userdataModel.NextLevelLeader.Trim().ToUpper();
            }
            if (string.IsNullOrEmpty(userdataModel.Email))    //邮箱
            {
                userdataModel.Email = "";
            }
            else
            {
                userdataModel.Email = userdataModel.Email.Trim().ToLower();
            }
            if (string.IsNullOrEmpty(userdataModel.Department))    //部门
            {
                userdataModel.Department = "";
            }
            else
            {
                userdataModel.Department = userdataModel.Department.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.ChineseName))    //中文名
            {
                userdataModel.ChineseName = "";
            }
            else
            {
                userdataModel.ChineseName = userdataModel.ChineseName.Trim();
            }
            if (string.IsNullOrEmpty(userdataModel.AllManager))    //所有主管
            {
                userdataModel.AllManager = "";
            }
            else
            {
                userdataModel.AllManager = userdataModel.AllManager.Trim().ToUpper();
            }
            if (string.IsNullOrEmpty(userdataModel.AgainPassword))    //确认密码
            {
                ViewBag.returnStr = "用户确认密码不能为空, 请确认后重试";
                return View();
            }
            else
            {
                userdataModel.AgainPassword = userdataModel.AgainPassword.Trim();
            }
            if (userdataModel.Password != userdataModel.AgainPassword)
            {
                ViewBag.returnStr = "用户密码和确认密码不一致, 请确认后重试";
                return View();
            }
string logonUrl = Url.Action("LogOn", "Account");
            long LogID = 0;
            TRMS.Model.Member.User user = new Model.Member.User();
            user.ID = userdataModel.UserID;
            user.ChineseName = userdataModel.ChineseName;
            user.EnglishName = userdataModel.EnglishName;
            user.SiteName = userdataModel.SiteName;
            IDepartment DepartmentGroup = TRMS.BLL.FactoryManager.GetDepartmentItem();
            user.Department = DepartmentGroup.Load(userdataModel.Department);
            user.Leaders = userdataModel.AllManager;
            user.NextLeaveLeader = userdataModel.NextLevelLeader;
            user.Email = userdataModel.Email;
            user.WorkPhone = userdataModel.WorkPhone;
            user.MobilePhone = userdataModel.MobilePhone;
            user.PasswordEncrypt = userdataModel.Password;
            IUser UserGroup = TRMS.BLL.FactoryManager.GetUserFac();
            if (UserGroup.Add(user, User.Identity.Name, out LogID))
            {
                if (string.IsNullOrEmpty(userdataModel.Email))     //试用
                {
                    ViewBag.returnStr = string.Format("恭喜你,你可以试用30天, 点击<a href=\"{0}\">这里</a>返回到登录页面", logonUrl);
                }
                else                       //绑定邮件
                {
                    ViewBag.returnStr = string.Format("验证邮件已发送到你的邮箱 {0}, 请注意查收", userdataModel.Email);
                }
            }
            else
            {
                ViewBag.returnStr = "用户注册失败,请确认后重试";
            }
            return View();
        }       
        public ActionResult BindEmail(string id)
        {
            TRMS.Model.Service.Verify verifyitem = new Model.Service.Verify();
            if (TRMS.BLL.TRMSCache.Instance.GetCache<TRMS.Model.Service.Verify>(id.ToString(), out verifyitem))    
            {
                ViewBag.CacheID = id;
            }
            else          //缓存失效
            {
                ViewBag.WarningData = "注册绑定邮件中的链接已失效,请输入工号和邮箱重新发送";
            }
            return View();
        }        
        [HttpPost]
        public JsonResult VertifyUserID(string id, string userid)
        {
            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(userid))
            {
                var JsonData = new Model.ActionResult { Result = false, Message = "缓存ID或者用户名不能为空,请确认后重试" };
                return Json(JsonData);
            }
            userid = userid.Trim().ToUpper();
            TRMS.Model.Service.Verify verifyitem = new Model.Service.Verify();
            if (TRMS.BLL.TRMSCache.Instance.GetCache<TRMS.Model.Service.Verify>(id.ToString(), out verifyitem))
            {
                if (verifyitem.UserID == userid)
                {
                    string logonUrl = Url.Action("LogOn","Account");
                    var JsonData = new TRMS.Model.ActionResult { Result = true, Value = string.Format("恭喜你注册成功,点击<a href=\"{0}\">这里</a>返回到登录页面",logonUrl) };
                    TRMS.BLL.TRMSCache.Instance.RemoveCache<TRMS.Model.Service.Verify>(id.ToString());    //移除缓存
                    return Json(JsonData);
                }
                else
                {
                    var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "工号输入不正确,请确认后重试" };
                    return Json(JsonData);
                }
            }
            else    //没有获取到缓存
            {
                var JsonData = new TRMS.Model.ActionResult { Result = false, Message = "注册绑定邮件中的链接已失效,请输入工号和邮箱重新发送", Value = userid };
                return Json(JsonData);
            }
        }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace TRMS.BLL.Common
{
    public abstract class BaseAuthAttribute : System.Web.Mvc.AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return base.AuthorizeCore(httpContext);
        }
        public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("NULL filterContext");
            }
            if (OutputCacheAttribute.IsChildActionCacheActive(filterContext))
            {
                throw new InvalidOperationException("子操作缓存处于活动状态");
            }
            var httpContext = filterContext.HttpContext;
            if (httpContext == null)
            {
                throw new ArgumentNullException("NULL httpContext");
            }
            if (httpContext.User == null || (!httpContext.User.Identity.IsAuthenticated))
            {
                filterContext.Result = new HttpUnauthorizedResult();
                return;
            }
var AuthFac = TRMS.BLL.FactoryManager.GetAuthorizationFac();
            var resourceitem = AuthFac.FindOrCreateResource(new Model.Authorization.Resource
            {
                ID = this.ResourceID,
                ApplicationName = TRMSConfiguration.ApplicationName,
                Action = filterContext.ActionDescriptor.ActionName,
                Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                Description = this.Description,
                ResourceName = this.ResourceName,
                ResourceType = this.ResourceType
            });
int temp_denyid = 0;
            if (AuthFac.AuthByUserID(resourceitem.ID, httpContext.User.Identity.Name, out temp_denyid, true) != Model.Authorization.AuthorizeType.Allow)
            {
                throw new HttpUnhandledException(string.Format("用户访问授权失败,引起此错误的权限记录是 {0},若要继续访问,请联系管理员。", temp_denyid));
            }
}
public virtual Guid ResourceID { get; protected set; }
public virtual string ResourceName { get; set; }
protected virtual string ActionName { get; set; }
protected virtual string ControllerName { get; set; }
public virtual string Description { get; set; }
        public virtual Model.Authorization.ResourceType ResourceType { get; set; }
    }
    [AttributeUsage(AttributeTargets.Method)]
    public class ActionAuthAttribute : BaseAuthAttribute
    {
        public ActionAuthAttribute(string ResourceID, string resourcename)
        {
            this.ResourceType = Model.Authorization.ResourceType.Action;
            this.ResourceID = Guid.Parse(ResourceID);
            this.ResourceName = resourcename;
        }
        public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
        {
            this.ActionName = filterContext.ActionDescriptor.ActionName;
            this.ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            base.OnAuthorization(filterContext);
        }
    }
    [AttributeUsage(AttributeTargets.Class)]
    public class ControllerAuthAttribute : BaseAuthAttribute
    {
        public ControllerAuthAttribute(string ResourceID, string resourcename)
        {
            this.ResourceType = Model.Authorization.ResourceType.Controller;
            this.ResourceID = Guid.Parse(ResourceID);
            this.ResourceName = resourcename;
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            this.ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            base.OnAuthorization(filterContext);
        }
    }
}
                    
                
                
            
        
浙公网安备 33010602011771号