Exemple #1
0
        public HttpResponseMessage inquiry(MasterInquiryUserRoleParam model)
        {
            try
            {
                model.username = model.username.Trim();
                model.name     = model.name.Trim();

                var result = userRoleService.InquiryUserRoles(model);

                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Exemple #2
0
        public CommonSearchView <UserRole> InquiryUserRoles(MasterInquiryUserRoleParam model)
        {
            using (var ctx = new ConXContext())
            {
                //define model view
                CommonSearchView <UserRole> view = new ModelViews.CommonSearchView <UserRole>()
                {
                    pageIndex   = model.pageIndex - 1,
                    itemPerPage = model.itemPerPage,
                    totalItem   = 0,

                    datas = new List <UserRole>()
                };

                //query data
                List <UserRole> userRoles = ctx.UserRoles
                                            .Where(x =>
                                                   (x.roleName.Contains(model.name) || model.name == null) &&
                                                   (x.status == model.status || model.status == null) &&
                                                   x.isPC == model.isPC &&
                                                   (x.createUser == model.createUser || model.createUser.ToLower() == "admin")
                                                   )
                                            .OrderBy(o => o.createDatetime)
                                            .ToList();

                //count , select data from pageIndex, itemPerPage
                view.totalItem = userRoles.Count;
                userRoles      = userRoles.Skip(view.pageIndex * view.itemPerPage)
                                 .Take(view.itemPerPage)
                                 .ToList();

                //prepare model to modelView
                foreach (var i in userRoles)
                {
                    view.datas.Add(i);
                }

                //return data to contoller
                return(view);
            }
        }