Exemple #1
0
        public ActionResult SearchSelectSubAreaList(SelectSubAreaSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search SelectSubArea").ToInputLogString());

            try
            {
                if (ModelState.IsValid)
                {
                    _subAreaFacade = new SubAreaFacade();
                    var model = new AreaViewModel();
                    model.SelectSearchFilter = searchFilter;

                    model.SelectSubAreaList = _subAreaFacade.GetSelectSubAreaList(model.SelectSearchFilter);
                    ViewBag.PageSize        = model.SelectSearchFilter.PageSize;

                    return(PartialView("~/Views/Area/_SelectSubAreaList.cshtml", model));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search SelectSubArea").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Exemple #2
0
        public IEnumerable <SubAreaItemEntity> GetSelectSubAreaList(SelectSubAreaSearchFilter searchFilter)
        {
            var resultQuery = (from subArea in _context.TB_M_SUBAREA
                               from createUser in _context.TB_R_USER.Where(x => x.USER_ID == subArea.CREATE_USER).DefaultIfEmpty()
                               from updateUser in _context.TB_R_USER.Where(x => x.USER_ID == subArea.UPDATE_USER).DefaultIfEmpty()
                               where ((searchFilter.SubAreaName == null || subArea.SUBAREA_NAME.Contains(searchFilter.SubAreaName)) && (searchFilter.SubAreaCode == null || SqlFunctions.StringConvert(subArea.SUBAREA_CODE).Contains(searchFilter.SubAreaCode)))
                               select new SubAreaItemEntity
            {
                SubAreaId = subArea.SUBAREA_ID,
                SubAreaName = subArea.SUBAREA_NAME,
                SubAreaCode = SqlFunctions.StringConvert(subArea.SUBAREA_CODE),
                IsActive = subArea.SUBAREA_IS_ACTIVE,
                UpdateUser = (updateUser != null
                                       ? new UserEntity
                {
                    PositionCode = updateUser.POSITION_CODE,
                    Firstname = updateUser.FIRST_NAME,
                    Lastname = updateUser.LAST_NAME
                }
                                       : null),
                CreateUser = (createUser != null
                                       ? new UserEntity
                {
                    PositionCode = createUser.POSITION_CODE,
                    Firstname = createUser.FIRST_NAME,
                    Lastname = createUser.LAST_NAME
                }
                                       : null),
                UpdateDateTime = subArea.UPDATE_DATE.HasValue ? subArea.UPDATE_DATE : subArea.CREATE_DATE
            });

            if (!string.IsNullOrEmpty(searchFilter.SubAreaIdList))
            {
                var subAreaIdArray = searchFilter.SubAreaIdList.Split(',').Select(s => Convert.ToInt32(s)).ToList();
                resultQuery = resultQuery.Where(q => !subAreaIdArray.Contains(q.SubAreaId.Value));
            }

            int startPageIndex = (searchFilter.PageNo - 1) * searchFilter.PageSize;

            searchFilter.TotalRecords = resultQuery.Count();

            if (startPageIndex >= searchFilter.TotalRecords)
            {
                startPageIndex      = 0;
                searchFilter.PageNo = 1;
            }

            resultQuery = SetSelectSubAreaListSort(resultQuery, searchFilter);
            return(resultQuery.Skip(startPageIndex).Take(searchFilter.PageSize).ToList());
        }
Exemple #3
0
 public IEnumerable <SubAreaItemEntity> GetSubAreaListById(SelectSubAreaSearchFilter searchFilter)
 {
     _subAreaDataAccess = new SubAreaDataAccess(_context);
     return(_subAreaDataAccess.GetSubAreaListById(searchFilter));
 }
Exemple #4
0
 private static IQueryable <SubAreaItemEntity> SetSelectSubAreaListSort(IQueryable <SubAreaItemEntity> subAreaList, SelectSubAreaSearchFilter searchFilter)
 {
     if (searchFilter.SortOrder.ToUpper(CultureInfo.InvariantCulture).Equals("ASC"))
     {
         switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture))
         {
         default:
             return(subAreaList.OrderBy(a => a.SubAreaName));
         }
     }
     else
     {
         switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture))
         {
         default:
             return(subAreaList.OrderByDescending(a => a.SubAreaName));
         }
     }
 }