Esempio n. 1
0
 public AccountController()
 {
     FSservice         = ServiceLocator.GetService <FileSystemService>();
     _pdfService       = ServiceLocator.GetService <PDFServiceSoapClient>();
     _conSrv           = ServiceLocator.GetService <ConfirmationService>();
     _userActionLogSrv = ServiceLocator.GetService <UserActionService>();
 }
Esempio n. 2
0
 public ReportsController()
 {
     this.NCPurchasSrv     = ServiceLocator.GetService <NCPurchaseService>();
     this.NCDataUpload     = ServiceLocator.GetService <NCDataUploadService>();
     this.NCRegisterSrv    = ServiceLocator.GetService <NCRegisterService>();
     this.userActionLogSrv = ServiceLocator.GetService <UserActionService>();
     this.service          = ServiceLocator.GetService <ReportService>();
     this.PurchaseService  = ServiceLocator.GetService <PurchaseService>();
     musicService          = ServiceLocator.GetService <MusicService>();
 }
Esempio n. 3
0
        public int Reading(ReadForm form)
        {
            form.ByUserID = form.UserID; // byUserID has to be the UserID
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new UserActionService(uow);
                var id      = service.Reading(form);

                var read = service.SummarizeRead(form);
                return(read);
            }
        }
Esempio n. 4
0
        public double Rating(RateForm form)
        {
            form.ByUserID = form.UserID; // byUserID has to be the UserID
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new UserActionService(uow);
                var id      = service.Rating(form);

                var vote = service.SummarizeRate(form);
                return(vote);
            }
        }
Esempio n. 5
0
        public int Viewing(ViewForm form)
        {
            form.ByUserID = form.UserID; // byUserID has to be the UserID
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new UserActionService(uow);
                var id      = service.Viewing(form);

                var view = service.SummarizeView(form);
                return(view);
            }
        }
Esempio n. 6
0
        public int AddComment(CommentForm commentForm)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new CommentService(uow);
                var id      = service.SaveChanges(commentForm);

                // new comment, increase comment count
                if (commentForm.ID == 0)
                {
                    var userActionService = new UserActionService(uow);
                    userActionService.SummarizeComment(commentForm);
                }

                return(id);
            }
        }
Esempio n. 7
0
        public UserActionDetail Get(ViewForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new UserActionService(uow);


                var userAction = new UserActionDetail();
                userAction.Voted =
                    service.View <UserVote>().Where(w => w.SourceTable == form.SourceTable && w.SourceID == form.SourceID && w.UserID == form.UserID).Select(s => s.Vote).SingleOrDefault();

                userAction.QualityRated =
                    service.View <UserRate>().Where(w => w.SourceTable == form.SourceTable && w.SourceID == form.SourceID && w.UserID == form.UserID).Select(s => s.Rate).SingleOrDefault();

                userAction.IsRead = service.View <UserRead>().Where(w => w.SourceTable == form.SourceTable && w.SourceID == form.SourceID && w.UserID == form.UserID).Any();

                return(userAction);
            }
        }
        public async Task <IHttpActionResult> GetAsync()
        {
            // check user type by UserType field of UserCookie
            // if the user is not an admin return 403 Forbidden
            CookieHeaderValue cookie = Request.Headers.GetCookies(BLL.Utils.UserCookieHelper.userCookieName).FirstOrDefault();

            if (cookie != null && cookie[BLL.Utils.UserCookieHelper.userCookieName].Values["UserType"] != UserType.Admin.ToString())
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            // return user actions
            var userActionDTOs = await UserActionService.GetAllUserActions();

            var userActionVMs = AMapper.Mapper.Map <IEnumerable <UserActionGetDetailDTO>, IEnumerable <UserActionViewModel> >(userActionDTOs);

            if (userActionVMs.Count() == 0)
            {
                return(NotFound());
            }
            return(Ok(userActionVMs));
        }
        public async Task GenerateReportFile()
        {
            // get date and report file path
            string reportPath = GetReportPath();

            // get and map data to report
            var rawData = await UserActionService.GetUserActionsByDate(DateTime.Now.AddDays(-1));

            var reportData = AMapper.Mapper.Map <IEnumerable <UserActionGetDetailDTO>, IEnumerable <UserActionReportDTO> >(rawData);

            using (var writer = new StreamWriter(reportPath))
                using (var csvWriter = new CsvWriter(writer,
                                                     System.Globalization.CultureInfo.CreateSpecificCulture("en-US")))
                {
                    csvWriter.Configuration.HasHeaderRecord = true;
                    csvWriter.Configuration.AutoMap <UserActionReportDTO>();

                    csvWriter.WriteHeader <UserActionReportDTO>();
                    csvWriter.NextRecord();
                    csvWriter.WriteRecords(reportData);

                    writer.Flush();
                }
        }
Esempio n. 10
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            //return;
            //base.OnAuthorization(filterContext);

            //去session,使用分布式缓存完成登录
            if (Session["UserLogin"] == null)
            {
                filterContext.Result = new RedirectResult(Url.Action("Index", "UserLogin"));
                return;
            }
            UserLogin = Session["UserLogin"] as UserInfoViewModel;

            //           #region 登录验证
            //	    //1、获取客户端标识
            //           if (Request.Cookies.Get("loginId") == null)
            //           {
            //               filterContext.Result = new RedirectResult(Url.Action("Index", "UserLogin"));
            //               return;
            //           }
            //           string key=Request.Cookies.Get("loginId").Value;
            //           //2、与分布式缓存进行通信,获取对象
            //           MmHelper helper=new MmHelper();
            //           UserLogin = helper.Get(key) as UserInfoViewModel;
            //           //3、判断是否登录
            //           if (UserLogin == null)
            //           {
            //               filterContext.Result = new RedirectResult(Url.Action("Index", "UserLogin"));
            //               return;
            //           }
            //           //4、设置超时滑动时间
            //           helper.Set(key, UserLogin, DateTime.Now.AddMinutes(20));
            //#endregion

            #region 验证是否有访问权限
            //留个后门,给管理方便,生产环境下不存在这句代码
            if (UserLogin.UserName.ToLower().Equals("admin"))
            {
                return;
            }

            //1、准备工作,拿到用户,拿到权限信息
            UserInfo   userInfo       = UserInfoService.GetById(UserLogin.UserId);
            string     controllerName = RouteData.GetRequiredString("controller");
            string     actionName     = RouteData.GetRequiredString("action");
            ActionInfo actionInfo     = ActionInfoService.GetList(a =>
                                                                  (a.ControllerName.ToLower().Equals(controllerName.ToLower()))
                                                                  &&
                                                                  (a.ActionName.ToLower().Equals(actionName.ToLower()))
                                                                  &&
                                                                  a.IsDelete == false)
                                        .FirstOrDefault();
            if (actionInfo == null)
            {
                filterContext.Result = new RedirectResult("/Error.html");
            }

            //2、查询否决表,看有没有数据
            UserAction userAction = UserActionService.GetList(ua =>
                                                              (ua.UserId == userInfo.UserId)
                                                              &&
                                                              (ua.ActionId == actionInfo.ActionId)).FirstOrDefault();
            if (userAction != null)
            {
                //2.1否决表中有数据
                if (userAction.IsAllow)
                {
                    //2.1.1允许
                }
                else
                {
                    //2.1.2拒绝
                    filterContext.Result = new RedirectResult("/NoAllow.html");
                }
            }
            else
            {
                //2.2否决表中无数据,则通过用户找角色,通过角色找权限
                var result = from r in userInfo.RoleInfo
                             from a in r.ActionInfo
                             where a.ActionId == actionInfo.ActionId
                             select a;
                if (result.Count() > 0)
                {
                    //2.2.1有权限
                }
                else
                {
                    //2.2.2无权限
                    filterContext.Result = new RedirectResult("/NoAllow.html");
                }
            }
            #endregion
        }
 public UserActionReportHelper()
 {
     UserActionService = new UserActionService();
     AMapper           = new AMapper();
 }
Esempio n. 12
0
 public UserManager(DataBaseContext db)
 {
     userService   = new UserService(db);
     clientService = new ClientService(db);
     uaService     = new UserActionService(db);
 }
Esempio n. 13
0
        public ActionResult Index()
        {
            //ViewData.Model = ActionInfoService
            //   .GetList(a => (a.IsDelete == false) && (a.IsMenu == true))
            //   .Select(a => new MenuViewModel()
            //   {
            //       ActionTitle = a.ActionTitle,
            //       ActionName = a.ActionName,
            //       ControllerName = a.ControllerName,
            //       MenuIcon = a.MenuIcon
            //   }).ToList();

            #region 主菜单过滤
            //1准备目标集合
            List <MenuViewModel> listMenu = new List <MenuViewModel>();
            //1.1获取所有的桌面菜单
            List <ActionInfo> list = ActionInfoService.GetList(a => a.IsDelete == false && a.IsMenu == true).ToList();
            //1.2获取当前登录的用户的对象
            UserInfo userInfo = UserInfoService.GetById(UserLogin.UserId);
            //1.3遍历所有桌面菜单,逐个判断是否有权限
            foreach (var actionInfo in list)
            {
                //根据当前数据,构造一个菜单对象
                MenuViewModel menu = new MenuViewModel()
                {
                    ActionTitle    = actionInfo.ActionTitle,
                    ControllerName = actionInfo.ControllerName,
                    ActionName     = actionInfo.ActionName,
                    MenuIcon       = actionInfo.MenuIcon
                };

                //如果当前用户是admin,则不需要判断直接进入
                if (UserLogin.UserName.Equals("admin"))
                {
                    listMenu.Add(menu);
                    continue;
                }


                //2、查找否决中是否允许,如果允许,直接加入目标集合
                if (UserActionService.GetList(ua =>
                                              (ua.ActionId == actionInfo.ActionId) &&
                                              (ua.UserId == UserLogin.UserId) &&
                                              (ua.IsAllow == true)).Count() > 0)
                {
                    listMenu.Add(menu);
                    continue;
                }

                //3、如果特权没有允许,则查找角色-权限过程
                var result1 = from r in userInfo.RoleInfo//from a in list<a>
                              from a in r.ActionInfo
                              where a.ActionId == actionInfo.ActionId
                              select a;
                if (result1.Count() > 0)
                {
                    listMenu.Add(menu);
                }

                //4、排除拒绝的特殊权限
                var result2 = from ua in userInfo.UserAction
                              where ua.ActionId == actionInfo.ActionId
                              &&
                              ua.IsAllow == false
                              select ua;
                if (result2.Count() > 0)
                {
                    listMenu.Remove(menu);
                }
            }
            #endregion

            return(View(listMenu));
        }