public IActionResult GetAllPaginatedWithDetail([FromQuery] GetAllPaginatedRequestModel requestModel, [FromHeader] string displayLanguage)
        {
            var responseModel = new ApiResponseModel <PaginatedList <MoveWithDetail> >();

            responseModel.DisplayLanguage = displayLanguage;

            try
            {
                var searchFilter = new MoveSearchFilter();
                searchFilter.CurrentPage           = requestModel.CurrentPage.HasValue ? requestModel.CurrentPage.Value : 1;
                searchFilter.PageSize              = requestModel.PageSize.HasValue ? requestModel.PageSize.Value : 10;
                searchFilter.SortOn                = requestModel.SortOn;
                searchFilter.SortDirection         = requestModel.SortDirection;
                searchFilter.Filter_Appliance_Name = requestModel.Appliance_Name;
                searchFilter.Filter_Lab_Name       = requestModel.Lab_Name;
                responseModel.Data = _moveService.GetAllPaginatedWithDetailBySearchFilter(searchFilter);

                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Success;
                responseModel.ResultStatusMessage = "Success";
                return(Ok(responseModel));
            }
            catch (Exception ex)
            {
                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Error;
                responseModel.ResultStatusMessage = ex.Message;
                responseModel.Data = null;
                return(StatusCode(StatusCodes.Status500InternalServerError, responseModel));
            }
        }
Example #2
0
        public ActionResult List(ListViewModel model)
        {
            // filter bilgilerinin default boş değerlerle doldurulması sağlanıyor
            if (model.Filter == null)
            {
                model.Filter = new ListFilterViewModel();
            }

            if (!model.CurrentPage.HasValue)
            {
                model.CurrentPage = 1;
            }

            if (!model.PageSize.HasValue)
            {
                model.PageSize = 10;
            }

            MoveSearchFilter searchFilter = new MoveSearchFilter();

            searchFilter.CurrentPage           = model.CurrentPage.HasValue ? model.CurrentPage.Value : 1;
            searchFilter.PageSize              = model.PageSize.HasValue ? model.PageSize.Value : 10;
            searchFilter.SortOn                = model.SortOn;
            searchFilter.SortDirection         = model.SortDirection;
            searchFilter.Filter_Appliance_Name = model.Filter.Filter_Appliance_Name;
            searchFilter.Filter_Lab_Name       = model.Filter.Filter_Lab_Name;
            model.CurrentLanguageTwoChar       = SessionHelper.CurrentLanguageTwoChar;

            var apiResponseModel = _moveService.GetAllPaginatedWithDetailBySearchFilter(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar, searchFilter);

            if (apiResponseModel.ResultStatusCode == ResultStatusCodeStatic.Success)
            {
                model.DataList = apiResponseModel.Data;
            }
            else
            {
                ViewBag.ErrorMessage     = apiResponseModel.ResultStatusMessage;
                ViewBag.ErrorMessageList = apiResponseModel.ErrorMessageList;
                return(View(model));
            }
            return(View(model));
        }
Example #3
0
        public ActionResult List(string errorMessage = default)
        {
            if (!string.IsNullOrEmpty(errorMessage))
            {
                ViewBag.ErrorMessage = errorMessage;
            }

            ListViewModel model = new ListViewModel();

            model.Filter      = new ListFilterViewModel();
            model.CurrentPage = 1;
            model.PageSize    = 10;
            MoveSearchFilter searchFilter = new MoveSearchFilter();

            searchFilter.CurrentPage           = model.CurrentPage.HasValue ? model.CurrentPage.Value : 1;
            searchFilter.PageSize              = model.PageSize.HasValue ? model.PageSize.Value : 10;
            searchFilter.SortOn                = model.SortOn;
            searchFilter.SortDirection         = model.SortDirection;
            searchFilter.Filter_Appliance_Name = model.Filter.Filter_Appliance_Name;
            searchFilter.Filter_Lab_Name       = model.Filter.Filter_Lab_Name;
            model.CurrentLanguageTwoChar       = SessionHelper.CurrentLanguageTwoChar;

            var apiResponseModel = _moveService.GetAllPaginatedWithDetailBySearchFilter(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar, searchFilter);

            if (apiResponseModel.ResultStatusCode == ResultStatusCodeStatic.Success)
            {
                model.DataList = apiResponseModel.Data;
            }
            else
            {
                ViewBag.ErrorMessage     = apiResponseModel.ResultStatusMessage;
                ViewBag.ErrorMessageList = apiResponseModel.ErrorMessageList;
                return(View(model));
            }
            return(View(model));
        }
Example #4
0
        public PaginatedList <MoveWithDetail> GetAllPaginatedWithDetailBySearchFilter(MoveSearchFilter searchFilter)
        {
            PaginatedList <MoveWithDetail> resultList = new PaginatedList <MoveWithDetail>(new List <MoveWithDetail>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection);

            using (AppDBContext dbContext = new AppDBContext(_config))
            {
                var query = from m in dbContext.Move
                            from a in dbContext.Appliance.Where(x => x.Id == m.ApplianceId).DefaultIfEmpty()
                            from l in dbContext.Lab.Where(x => x.Id == m.LabId).DefaultIfEmpty()
                            select new MoveWithDetail()
                {
                    Id           = m.Id,
                    LabId        = m.LabId,
                    ApplianceId  = m.ApplianceId,
                    EntranceDate = m.EntranceDate,
                    ExitDate     = m.ExitDate,

                    Appliance_Name = a == null ? String.Empty : a.Name,
                    Lab_Name       = l == null ? String.Empty : l.Name
                };

                // filtering
                if (!string.IsNullOrEmpty(searchFilter.Filter_Appliance_Name))
                {
                    query = query.Where(r => r.Appliance_Name.Contains(searchFilter.Filter_Appliance_Name));
                }

                if (!string.IsNullOrEmpty(searchFilter.Filter_Lab_Name))
                {
                    query = query.Where(r => r.Lab_Name.Contains(searchFilter.Filter_Lab_Name));
                }

                // asnotracking
                query = query.AsNoTracking();

                //total count
                var totalCount = query.Count();

                //sorting
                if (!string.IsNullOrEmpty(searchFilter.SortOn))
                {
                    // using System.Linq.Dynamic.Core; nuget paketi ve namespace eklenmelidir, dynamic order by yapmak icindir
                    query = query.OrderBy(searchFilter.SortOn + " " + searchFilter.SortDirection.ToUpper());
                }
                else
                {
                    // deefault sıralama vermek gerekiyor yoksa skip metodu hata veriyor ef 6'da -- 28.10.2019 15:40
                    // https://stackoverflow.com/questions/3437178/the-method-skip-is-only-supported-for-sorted-input-in-linq-to-entities
                    query = query.OrderBy(r => r.Id);
                }

                //paging
                query = query.Skip((searchFilter.CurrentPage - 1) * searchFilter.PageSize).Take(searchFilter.PageSize);


                resultList = new PaginatedList <MoveWithDetail>(
                    query.ToList(),
                    totalCount,
                    searchFilter.CurrentPage,
                    searchFilter.PageSize,
                    searchFilter.SortOn,
                    searchFilter.SortDirection
                    );
            }

            return(resultList);
        }
Example #5
0
        //api ile bağlandıgımız servisler
        public ApiResponseModel <PaginatedList <MoveWithDetail> > GetAllPaginatedWithDetailBySearchFilter(string userToken, string displayLanguage, MoveSearchFilter searchFilter)
        {
            ApiResponseModel <PaginatedList <MoveWithDetail> > result = new ApiResponseModel <PaginatedList <MoveWithDetail> >()
            {
                Data = new PaginatedList <MoveWithDetail>(new List <MoveWithDetail>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection)
            };

            //portal api'den çekme işlemi
            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(ConfigHelper.ApiUrl);
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userToken);
                httpClient.DefaultRequestHeaders.Add("DisplayLanguage", displayLanguage);
                HttpResponseMessage response = httpClient.GetAsync(string.Format("v1/Move?CurrentPage={0}&PageSize={1}&SortOn={2}&SortDirection={3}&Appliance_Name={4}&Lab_Name",
                                                                                 searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection, searchFilter.Filter_Appliance_Name, searchFilter.Filter_Lab_Name)).Result;
                result = response.Content.ReadAsJsonAsync <ApiResponseModel <PaginatedList <MoveWithDetail> > >().Result;
            }
            return(result);
        }