public static List <T> PaginateSearch <T>(this List <T> list, PaginationSearchDTO paginationSearchDTO)
 {
     return(list
            .Skip((paginationSearchDTO.Page - 1) * paginationSearchDTO.RecordsPerPage)
            .Take(paginationSearchDTO.RecordsPerPage)
            .ToList());
 }
        public async Task <ActionResult> GetProductsByCategory([FromQuery] PaginationSearchDTO paginationDTO, long categoryId)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion
                List <Product> list = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.CategoryId == categoryId && x.Status == Status.Online)
                           .Include(x => x.Category)
                           .Include(x => x.Store)
                           .OrderByDescending(c => c.Id).ToListAsync();
                }

                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.CategoryId == categoryId && x.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.Status == Status.Online)
                           .Include(x => x.Category)
                           .Include(x => x.Store)
                           .OrderByDescending(c => c.Id).ToListAsync();
                }

                List <ProductDetailsDTO> productVMs = new();
                foreach (var item in list)
                {
                    ProductDetailsDTO itemDTO = new();
                    itemDTO.Product = item;
                    itemDTO.Colors  = JsonConvert.DeserializeObject <List <string> >(item.Colors);
                    itemDTO.Images  = JsonConvert.DeserializeObject <List <string> >(item.Image);
                    productVMs.Add(itemDTO);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, productVMs);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #3
0
        public async Task <ActionResult> GetAllStoresAdmin([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <Store> list = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online)
                           .Include(x => x.Currency)
                           .Include(x => x.City).ThenInclude(x => x.Country)
                           .Include(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .Include(x => x.StoreCountries).ThenInclude(x => x.Country)
                           .Include(x => x.StoreCities).ThenInclude(x => x.City)
                           .Include(x => x.StoreUsers).ThenInclude(x => x.User)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }
                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.Status == Status.Online)
                           .Include(x => x.Currency)
                           .Include(x => x.City).ThenInclude(x => x.Country)
                           .Include(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .Include(x => x.StoreCountries).ThenInclude(x => x.Country)
                           .Include(x => x.StoreCities).ThenInclude(x => x.City)
                           .Include(x => x.StoreUsers).ThenInclude(x => x.User)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, list);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #4
0
        //New
        public static async Task <PaginatedResponse <T> > GetHelper2 <T>(this IHttpService httpService, string url,
                                                                         PaginationSearchDTO paginationSearchDTO)
        {
            string newURL = "";

            if (url.Contains("?"))
            {
                newURL = $"{url}&page={paginationSearchDTO.Page}&recordsPerPage={paginationSearchDTO.RecordsPerPage}&searchText={paginationSearchDTO.SearchText}";
            }
            else
            {
                newURL = $"{url}?page={paginationSearchDTO.Page}&recordsPerPage={paginationSearchDTO.RecordsPerPage}&searchText={paginationSearchDTO.SearchText}";
            }

            var httpResponse = await httpService.GetPagination <T>(newURL);

            var totalAmountPages  = int.Parse(httpResponse.HttpResponseMessage.Headers.GetValues("totalAmountPages").FirstOrDefault());
            var totalAmount       = long.Parse(httpResponse.HttpResponseMessage.Headers.GetValues("totalAmount").FirstOrDefault());
            var paginatedResponse = new PaginatedResponse <T>
            {
                Response         = httpResponse.Response,
                TotalAmountPages = totalAmountPages,
                TotalAmount      = totalAmount
            };

            return(paginatedResponse);
        }
        public async Task <ActionResult> GetAllCategoriesAdmin([FromQuery] PaginationSearchDTO paginationSearchDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion
                List <CategoryDTO> categoryVMList = new();
                List <Category>    list           = new();

                if (String.IsNullOrWhiteSpace(paginationSearchDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online && x.CategoryLevel == CategoryLevel.Category)
                           .Include(x => x.Parent).OrderByDescending(x => x.Id).ToListAsync();
                }
                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Name_en.ToLower().Contains(paginationSearchDTO.SearchText.ToLower()) &&
                                  x.Status == Status.Online && x.CategoryLevel == CategoryLevel.Category)
                           .Include(x => x.Parent)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }

                foreach (var category in list)
                {
                    CategoryDTO categoryVM = new()
                    {
                        Category        = category,
                        UpperCategories = await _entityServices.GetUpperCategories(category),
                        ChildCategories = await _entityServices.GetChildCategories(category)
                    };
                    categoryVMList.Add(categoryVM);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationSearchDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationSearchDTO);

                var page       = paginationSearchDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationSearchDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, categoryVMList);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Get([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <Notification> list = new();

                var user = await _userCServices.GetCurrent(User.Identity.Name);

                long userId = user != null ? user.Id : 0;

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.UserCId == userId)
                           .OrderByDescending(x => x.NotificationTime).ToListAsync();
                }

                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Body.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.UserCId == userId)
                           .OrderByDescending(x => x.NotificationTime)
                           .ToListAsync();
                }

                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, list);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #7
0
 public async Task <PaginatedResponse <List <IndexStoresUser> > > GetAllStoresUser(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <IndexStoresUser> >($"{url}/GetAllStoresUser", paginationDTO));
 }
 public async Task <PaginatedResponse <List <UserABDTO> > > GetFreezedUsers(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <UserABDTO> >($"{url}/GetFreezedUsers", paginationSearchDTO));
 }
 public async Task <PaginatedResponse <List <Product> > > GetProductsByCategoryAdmin(PaginationSearchDTO paginationDTO, long categoryId)
 {
     return(await _httpService.GetHelper2 <List <Product> >($"{url}/GetProductsByCategoryAdmin/{categoryId}", paginationDTO));
 }
 public async Task <PaginatedResponse <List <Product> > > GetProductsAdmin(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <Product> >($"{url}/GetProductsAdmin", paginationSearchDTO));
 }
Beispiel #11
0
 public async Task <PaginatedResponse <List <Store> > > GetStoresByTagAdmin(PaginationSearchDTO paginationDTO, long tagId)
 {
     return(await _httpService.GetHelper2 <List <Store> >($"{url}/GetStoresByTagAdmin/{tagId}", paginationDTO));
 }
 public async Task <PaginatedResponse <List <EmployeeDTO> > > GetStoreEmployeesByStore(PaginationSearchDTO paginationDTO, long storeId)
 {
     return(await _httpService.GetHelper2 <List <EmployeeDTO> >($"{url}/GetStoreEmployeesByStore/{storeId}", paginationDTO));
 }
Beispiel #13
0
        //public async Task<List<Store>> GetMyStoresAll()
        //{
        //    var response = await _httpService.Get2<List<Store>>($"{url}/GetMyStoresAll");
        //    if (!response.Success)
        //        throw new ApplicationException(await response.GetBody());
        //    return response.Response;
        //}

        public async Task <PaginatedResponse <List <IndexRequestAdminStores> > > GetRequestAdmin(PaginationSearchDTO paginationDTO)
        {
            return(await _httpService.GetHelper2 <List <IndexRequestAdminStores> >($"{url}/GetRequestAdmin", paginationDTO));
        }
 public async Task <PaginatedResponse <List <CategoryDTO> > > GetAllCategoriesAdmin(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <CategoryDTO> >($"{url}/GetAllCategoriesAdmin", paginationSearchDTO));
 }
Beispiel #15
0
        public async Task <ActionResult> GetAllStoresUser([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <Store>           list        = new();
                List <IndexStoresUser> storeVMList = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online)
                           .Include(x => x.Currency)
                           .Include(x => x.City).ThenInclude(x => x.Country)
                           .Include(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .Include(x => x.StoreCountries).ThenInclude(x => x.Country)
                           .Include(x => x.StoreCities).ThenInclude(x => x.City)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }
                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.Status == Status.Online)
                           .Include(x => x.Currency)
                           .Include(x => x.City).ThenInclude(x => x.Country)
                           .Include(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .Include(x => x.StoreCountries).ThenInclude(x => x.Country)
                           .Include(x => x.StoreCities).ThenInclude(x => x.City)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }

                var user = await _userCServices.GetCurrent(User.Identity.Name);

                long userId = user != null ? user.Id : 0;

                var myFavouriteStoresIds = (await _storeFollowersRepository.TableNoTracking
                                            .Where(x => x.UserCId == userId && x.Status == FollowStatus.Follow).ToListAsync()).Select(x => x.StoreId).ToList();

                foreach (var item in list)
                {
                    IndexStoresUser storeVM = new();

                    storeVM.Store = item;

                    storeVM.Status = myFavouriteStoresIds.Contains(item.Id) ? FollowStatus.Follow : FollowStatus.UnFollow;

                    storeVMList.Add(storeVM);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, storeVMList);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #16
0
 public async Task <PaginatedResponse <List <ProductUserDTO> > > GetIndexProductUser(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <ProductUserDTO> >($"{url}/GetIndexProductUser", paginationDTO));
 }
Beispiel #17
0
 public async Task <PaginatedResponse <List <MeasruingUnit> > > Get(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <MeasruingUnit> >(url, paginationSearchDTO));
 }
        public async Task <ActionResult> GetAllCategoriesUser([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion
                List <Category>            list           = new();
                List <IndexCategoriesUser> categoryVMList = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online && x.CategoryLevel == CategoryLevel.Category)
                           .Include(x => x.Parent)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }
                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Name_en.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.CategoryLevel == CategoryLevel.Category && x.Status == Status.Online)
                           .Include(x => x.Parent)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }

                long userId = (await _userCServices.GetCurrent(User.FindFirst(ClaimTypes.Name).Value)).Id;
                var  myFavouriteCategoriesIds = (await _categoryFollowers.TableNoTracking
                                                 .Where(x => x.UserCId == userId && x.Status == FollowStatus.Follow).ToListAsync()).Select(x => x.CategoryId).ToList();

                foreach (var item in list)
                {
                    IndexCategoriesUser category = new();

                    category.CategoryVM = new()
                    {
                        Category        = item,
                        UpperCategories = await _entityServices.GetUpperCategories(item),
                        ChildCategories = await _entityServices.GetChildCategories(item)
                    };

                    category.Status = myFavouriteCategoriesIds.Contains(item.Id) ? FollowStatus.Follow : FollowStatus.UnFollow;

                    categoryVMList.Add(category);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, categoryVMList);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #19
0
 public async Task <PaginatedResponse <List <CategoryForUser> > > GetCategoriesUser(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <CategoryForUser> >($"{url}/GetCategoriesUser", paginationDTO));
 }
Beispiel #20
0
        public async Task <ActionResult> GetRequestAdmin([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion
                List <IndexRequestAdminStores> storeVMList = new();
                List <StoreUsers> list = new();
                long userId            = (await _userCServices.GetCurrent(User.Identity.Name)).Id;

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _storeUsersRepository.TableNoTracking
                           .Where(x => x.UserCId == userId && x.Status == StoreUserStatus.Pending)
                           .Include(x => x.Store).ThenInclude(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }
                else
                {
                    list = await _storeUsersRepository.TableNoTracking
                           .Where(x => x.UserCId == userId && x.Status == StoreUserStatus.Pending && x.Store.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()))
                           .Include(x => x.Store).ThenInclude(x => x.StoreTags).ThenInclude(x => x.Tag)
                           .OrderByDescending(x => x.Id).ToListAsync();
                }

                foreach (var item in list)
                {
                    IndexRequestAdminStores storeVM = new()
                    {
                        Store  = item.Store,
                        Status = item.Status
                    };

                    List <int> roleDeserialize = JsonConvert.DeserializeObject <List <int> >(item.Role);

                    if (roleDeserialize.Contains(0))
                    {
                        storeVM.Admin = true;
                    }
                    if (roleDeserialize.Contains(1))
                    {
                        storeVM.ManageProducts = true;
                    }
                    if (roleDeserialize.Contains(2))
                    {
                        storeVM.ManageOrders = true;
                    }
                    if (roleDeserialize.Contains(3))
                    {
                        storeVM.ManageComments = true;
                    }

                    storeVMList.Add(storeVM);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, storeVMList);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #21
0
 public async Task <PaginatedResponse <List <Store> > > GetHiddenStores(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <Store> >($"{url}/GetHiddenStores", paginationDTO));
 }
Beispiel #22
0
 public async Task <PaginatedResponse <List <Store> > > GetAllFreezedStoresAdmin(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <Store> >($"{url}/GetAllFreezedStoresAdmin", paginationDTO));
 }
        public async Task <ActionResult> GetIndexProductUser([FromQuery] PaginationSearchDTO paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <Product> list = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online)
                           .Include(x => x.Currency)
                           .Include(x => x.Category)
                           .Include(x => x.Store)
                           .OrderByDescending(c => c.Id).ToListAsync();
                }

                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.Status == Status.Online && x.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()))
                           .Include(x => x.Currency)
                           .Include(x => x.Category)
                           .Include(x => x.Store)
                           .OrderByDescending(c => c.Id).ToListAsync();
                }

                List <ProductUserDTO> productVMs = new();

                Currency UserCurrency = await GetUserCurrency();

                foreach (var item in list)
                {
                    ProductUserDTO itemDTO = new();
                    itemDTO.Product      = item;
                    itemDTO.PriceUser    = GetPriceInUserCurrenct(item.Currency.Rate, UserCurrency.Rate, item.Price);
                    itemDTO.PriceUser1   = GetPriceInUserCurrenct(item.Currency.Rate, UserCurrency.Rate, item.Price1);
                    itemDTO.PriceUser2   = GetPriceInUserCurrenct(item.Currency.Rate, UserCurrency.Rate, item.Price2);
                    itemDTO.PriceUser3   = GetPriceInUserCurrenct(item.Currency.Rate, UserCurrency.Rate, item.Price3);
                    itemDTO.UserCurrency = UserCurrency;
                    productVMs.Add(itemDTO);
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, productVMs);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #24
0
 public async Task <PaginatedResponse <List <SAliDantel.Shared.DTOs.Store.IndexMyStores> > > GetMyStores(PaginationSearchDTO paginationDTO)
 {
     return(await _httpService.GetHelper2 <List <SAliDantel.Shared.DTOs.Store.IndexMyStores> >($"{url}/GetMyStores", paginationDTO));
 }
        public async Task <ActionResult> GetStoreEmployeesByStore([FromQuery] PaginationSearchDTO paginationDTO, long storeId)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <StoreUsers>  list          = new();
                List <EmployeeDTO> listEmployees = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.StoreId == storeId)
                           .Include(x => x.User).ThenInclude(x => x.City).ThenInclude(x => x.Country)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }

                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Where(x => x.StoreId == storeId && x.User.FirstName.ToLower().Contains(paginationDTO.SearchText.ToLower()))
                           .Include(x => x.User).ThenInclude(x => x.City).ThenInclude(x => x.Country)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }
                foreach (var item in list)
                {
                    EmployeeDTO employee = new();
                    employee.StoreUser = item;

                    List <int> roleDeserialize = JsonConvert.DeserializeObject <List <int> >(item.Role);

                    if (roleDeserialize.Contains(0))
                    {
                        employee.Admin = true;
                    }
                    if (roleDeserialize.Contains(1))
                    {
                        employee.ManageProducts = true;
                    }
                    if (roleDeserialize.Contains(2))
                    {
                        employee.ManageOrders = true;
                    }
                    if (roleDeserialize.Contains(3))
                    {
                        employee.ManageComments = true;
                    }
                    listEmployees.Add(employee);
                }

                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(listEmployees, paginationDTO.RecordsPerPage);

                listEmployees = listEmployees.PaginateSearch(paginationDTO);

                var page       = paginationDTO.Page;
                var totalPages = TotalPagesCount.Value(listCount, paginationDTO.RecordsPerPage);

                var result = ApiPaginationResponse.Create(HttpStatusCode.OK, page, totalPages, listEmployees);

                #region End the watch
                watch.Stop();
                result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
                #endregion

                return(Ok(result));
            }
            catch (Exception)
            {
                var result = ApiResponse.Create(HttpStatusCode.BadRequest, null, "InternalServerError_Error");
                return(Ok(result));
            }
        }
Beispiel #26
0
 public async Task <PaginatedResponse <List <HomePageHeader> > > Get(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <HomePageHeader> >(url, paginationSearchDTO));
 }
 public async Task <PaginatedResponse <List <ProductDetailsDTO> > > GetHiddenProducts(PaginationSearchDTO paginationDTO, long storeId)
 {
     return(await _httpService.GetHelper2 <List <ProductDetailsDTO> >($"{url}/GetHiddenProducts/{storeId}", paginationDTO));
 }
 public async Task <PaginatedResponse <List <WebApiLogs> > > Get(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <WebApiLogs> >(url, paginationSearchDTO));
 }
 public async Task <PaginatedResponse <List <PaymentMethodDTO> > > Get(PaginationSearchDTO paginationSearchDTO)
 {
     return(await _httpService.GetHelper2 <List <PaymentMethodDTO> >(url, paginationSearchDTO));
 }