示例#1
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));
            }
        }
        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));
            }
        }
        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));
            }
        }
示例#4
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));
            }
        }
        public async Task <ActionResult> GetStoreOrders(IndexStoreOrderVMRequest paginationDTO)
        {
            try
            {
                #region Start the watch
                var watch = new Stopwatch();
                watch.Start();
                #endregion

                List <Order> list = new();

                if (String.IsNullOrWhiteSpace(paginationDTO.SearchText))
                {
                    list = await _entityRepository.TableNoTracking
                           .Include(x => x.Product)
                           .Include(x => x.StorePaymentMethod).ThenInclude(x => x.PaymentMethod)
                           .Where(x => x.Product.StoreId == paginationDTO.StoreId)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }
                else
                {
                    list = await _entityRepository.TableNoTracking
                           .Include(x => x.Product)
                           .Include(x => x.StorePaymentMethod).ThenInclude(x => x.PaymentMethod)
                           .Where(x => x.Product.Name.ToLower().Contains(paginationDTO.SearchText.ToLower()) && x.Product.StoreId == paginationDTO.StoreId)
                           .OrderByDescending(x => x.Id)
                           .ToListAsync();
                }
                var listCount = list.Count;
                await HttpContext.InsertPaginationParametersInResponseList(list, paginationDTO.RecordsPerPage);

                list = list.PaginateSearch(paginationDTO.Pagination);

                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));
            }
        }
示例#6
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));
            }
        }
示例#7
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));
            }
        }
        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));
            }
        }
        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));
            }
        }
        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));
            }
        }