public async Task <ApiResponse> Get(string userName) { try { long userId = (await _userCServices.GetCurrent(userName)).Id; var query = _entityRepository.TableNoTracking.Where(x => x.UserCId == userId); var entities = await query.OrderByDescending(x => x.NotificationTime).ToListAsync(); return(ApiResponse.Create(HttpStatusCode.OK, entities)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task <ActionResult> Follow_UnFollow_Store(StoreFollowers entity) { #region Start the watch var watch = new Stopwatch(); watch.Start(); #endregion entity.UserCId = (await _userCServices.GetCurrent(User.Identity.Name)).Id; var result = await _favouritesServices.Follow_UnFollow_Store(entity); #region End the watch watch.Stop(); result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds; #endregion return(Ok(result)); }
public async Task <ApiResponse> Get(long orderId, string userName) { try { long userId = (await _userCServices.GetCurrent(userName)).Id; var entities = await _entityRepository.TableNoTracking .Where(x => x.OrderId == orderId) .Include(x => x.Order).ThenInclude(x => x.UserC) .Include(x => x.Order).ThenInclude(x => x.Product).ThenInclude(x => x.Store) .OrderBy(x => x.MessageDateTime).ToListAsync(); return(ApiResponse.Create(HttpStatusCode.OK, entities)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
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 <ApiResponse> Post(AddOrderVMRequest entity, string userName) { try { Order order = new() { UserCId = (await _userCServices.GetCurrent(userName)).Id, ProductId = entity.ProductId, OrderDate = DateTime.UtcNow, Quantity = entity.Quantity, Total = entity.Total, StorePaymentMethodId = entity.StorePaymentMethodId }; var newEntity = await _entityRepository.InsertAsync(order); return(ApiResponse.Create(HttpStatusCode.OK, newEntity.Id)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task <ApiResponse> GetStoreUserByStore(long storeId, string userName) { try { var userId = (await _userCServices.GetCurrent(userName)).Id; var storeUser = await _entityRepository.TableNoTracking.Where(x => x.UserCId == userId && x.StoreId == storeId).SingleOrDefaultAsync(); return(ApiResponse.Create(HttpStatusCode.OK, storeUser)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task <ApiResponse> GetDetailsForUser(long id, string userName) { try { CategoryDetailsForUser categoryDetailsForUser = new(); var entity = await _entityRepository.TableNoTracking .Include(x => x.Parent) .Include(x => x.CategoryFollowers).SingleOrDefaultAsync(x => x.Id == id); var user = _userCServices.GetCurrent(userName); var userId = user != null ? user.Id : 0; var categoryFollower = await _categoryFollowersRepository.TableNoTracking .Where(x => x.CategoryId == id && x.UserCId == userId).SingleOrDefaultAsync(); FollowStatus followStatus = categoryFollower != null ? categoryFollower.Status : FollowStatus.UnFollow; categoryDetailsForUser.Category = new CategoryForUser() { Category = entity, Status = followStatus }; var childCategories = await GetChildCategories(entity); foreach (var item in childCategories) { var childCategoryFollower = await _categoryFollowersRepository.TableNoTracking .Where(x => x.CategoryId == item.Id && x.UserCId == userId).SingleOrDefaultAsync(); FollowStatus childFollowStatus = childCategoryFollower != null ? childCategoryFollower.Status : FollowStatus.UnFollow; categoryDetailsForUser.ChildCategories.Add(new CategoryForUser() { Category = item, Status = childFollowStatus }); } return(ApiResponse.Create(HttpStatusCode.OK, categoryDetailsForUser)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task <ApiResponse> GetRolesForStore(long storeId, string userName) { List <EmployeeRole> roles = new(); try { var user = await _userCServices.GetCurrent(userName); if (user != null) { var entity = _entityRepository.TableNoTracking .Where(x => x.StoreId == storeId && x.UserCId == user.Id).SingleOrDefault(); roles = JsonConvert.DeserializeObject <List <EmployeeRole> >(entity.Role); } return(ApiResponse.Create(HttpStatusCode.OK, roles)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task <ActionResult> UserOrders(IndexOrderVMRequest paginationDTO) { try { #region Start the watch var watch = new Stopwatch(); watch.Start(); #endregion List <Order> 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) .Include(x => x.Product).ThenInclude(x => x.Store) .Include(x => x.StorePaymentMethod).ThenInclude(x => x.PaymentMethod) .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.UserCId == userId) .ToListAsync(); } if (paginationDTO.OrderStatus != null) { list = list.Where(x => x.Status == paginationDTO.OrderStatus).ToList(); } if (paginationDTO.From != null) { list = list.Where(x => x.OrderDate >= paginationDTO.From).ToList(); } if (paginationDTO.To != null) { list = list.Where(x => x.OrderDate <= paginationDTO.To).ToList(); } 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)); } }
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 <ApiResponse> Post(AddStoreVMRequest entity, string userName) { try { var user = await _userCServices.GetCurrent(userName); long max = 0; var query = await _entityRepository.TableNoTracking.FirstOrDefaultAsync(); if (query != null) { max = await _entityRepository.TableNoTracking.MaxAsync(x => x.Id); } Store store = new() { Name = entity.Name, Address = entity.Address, CityId = entity.CityId, CurrencyId = entity.CurrencyId, Image = entity.Image, Code = $"Store_{max + 1}", userCId = user.Id }; if (!string.IsNullOrWhiteSpace(entity.Image)) { var entityImage = Convert.FromBase64String(entity.Image); store.Image = await _fileService.SaveFile(entityImage, "jpg", path, store.Code); } var newEntity = await _entityRepository.InsertAsync(store); var storeId = newEntity.Id; foreach (var item in entity.Tags) { StoreTags x = new() { StoreId = storeId, TagId = item }; await _context.StoreTags.AddAsync(x); } foreach (var item in entity.Countries) { StoreCountries x = new() { StoreId = storeId, CountryId = item }; await _context.StoreCountries.AddAsync(x); } foreach (var item in entity.Cities) { StoreCities x = new() { StoreId = storeId, CityId = item }; await _context.StoreCities.AddAsync(x); } foreach (var item in entity.Users) { StoreUsers x = new() { StoreId = storeId, UserCId = item }; await _context.StoreUsers.AddAsync(x); } foreach (var item in entity.PaymentMethods) { StorePaymentMethods x = new() { StoreId = storeId, PaymentMethodId = item.PaymentMethodId, Details = item.Details }; await _context.StorePaymentMethods.AddAsync(x); } await _context.SaveChangesAsync(); StoreUsers storeUser = new(); storeUser.StoreId = newEntity.Id; storeUser.UserCId = user.Id; storeUser.Role = "[0,1,2,3]"; storeUser.Status = StoreUserStatus.Accepted; _storeUserRepository.Insert(storeUser); return(ApiResponse.Create(HttpStatusCode.OK, storeId)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
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)); } }