Пример #1
0
        public ActionResult Edit(Guid?id, SysController collection)
        {
            if (!ModelState.IsValid)
            {
                Edit(id);
                return(View(collection));
            }

            if (id.HasValue)
            {
                //清除原有数据
                _sysControllerSysActionService.Delete(a => a.SysControllerId.Equals(id.Value) && !collection.SysActionsId.Contains(a.SysActionId));
            }

            _sysControllerService.Save(id, collection);

            if (collection.SysActionsId != null)
            {
                foreach (
                    var actionid in
                    collection.SysActionsId.Where(
                        actionid =>
                        !_sysControllerSysActionService.GetAll()
                        .Where(b => b.SysControllerId.Equals(id.Value))
                        .Select(b => b.SysActionId)
                        .Contains(actionid)))
                {
                    _sysControllerSysActionService.Save(null, new SysControllerSysAction
                    {
                        SysControllerId = collection.Id,
                        SysActionId     = actionid
                    });
                }
            }

            _unitOfWork.Commit();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(string id, SysController collection)
        {
            if (!ModelState.IsValid)
            {
                Edit(id);
                return(View(collection));
            }

            if (!string.IsNullOrEmpty(id))
            {
                //清除原有数据
                _sysControllerSysActionService.Delete(a => a.SysControllerId.Equals(id) && !collection.SysActionsId.Contains(a.SysActionId));
            }

            _sysControllerService.Save(id, collection);

            if (collection.SysActionsId != null)
            {
                foreach (
                    var actionid in
                    collection.SysActionsId.Where(
                        actionid =>
                        !_sysControllerSysActionService.GetAll()
                        .Where(b => b.SysControllerId.Equals(id))
                        .Select(b => b.SysActionId)
                        .Contains(actionid)))
                {
                    _sysControllerSysActionService.Save(null, new SysControllerSysAction
                    {
                        SysControllerId = collection.Id,
                        SysActionId     = actionid
                    });
                }
            }

            await _unitOfWork.CommitAsync();

            return(new EditSuccessResult(id));
        }
Пример #3
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="filterContext">
        /// </param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            var viewDuration = Math.Round((DateTime.Now - _viewdatetimenow).TotalMilliseconds, 3);

            //记录用户访问记录
            var area       = (string)filterContext.RouteData.Values["area"];
            var action     = (string)filterContext.RouteData.Values["action"];
            var controller = (string)filterContext.RouteData.Values["controller"];


            var sysuserlog = new SysUserLog
            {
                Ip  = filterContext.HttpContext.Connection.RemoteIpAddress.ToString(),
                Url = filterContext.HttpContext.Request.GetDisplayUrl(),

                ViewDuration   = viewDuration,
                ActionDuration = _actionDuration,
                Duration       = Math.Round((DateTime.Now - _actiondatetimenow).TotalMilliseconds, 3),
                RequestType    = filterContext.HttpContext.Request.Method,
            };

            var sysControllerSysAction = _iSysControllerSysActionService.GetAll(a => a.SysController.ControllerName.Equals(controller) && a.SysController.SysArea.AreaName.Equals(area) && a.SysAction.ActionName.Equals(action)).OrderBy(a => a.SysController.SystemId).Select(a => new { a.Id, SysAreaName = a.SysController.SysArea.Name, SysControllerName = a.SysController.Name, SysActionName = a.SysAction.Name }).FirstOrDefault();


            if (sysControllerSysAction != null)
            {
                sysuserlog.SysArea       = sysControllerSysAction?.SysAreaName ?? area;
                sysuserlog.SysController = sysControllerSysAction?.SysControllerName ?? controller;
                sysuserlog.SysAction     = sysControllerSysAction?.SysActionName ?? action;
            }


            _sysUserLogService.SaveAsync(null, sysuserlog).Wait();

            _iUnitOfWork.CommitAsync().Wait();

            base.OnResultExecuted(filterContext);
        }