private void SearchByPrice(ref IIncludableQueryable <Product, ICollection <Color> > products, double?MinPrice, double?MaxPrice)
        {
            if (!products.Any())
            {
                return;
            }

            if (MinPrice == null && MaxPrice != null)
            {
                products = products.Where(c => c.price <= MaxPrice)
                           .Include(s => s.Sizes)
                           .Include(c => c.Colors);
            }
            else if (MinPrice != null && MaxPrice == null)
            {
                products = products.Where(c => c.price >= MinPrice)
                           .Include(s => s.Sizes)
                           .Include(c => c.Colors);
            }
            else if (MinPrice != null && MaxPrice != null)
            {
                products = products.Where(c => c.price >= MinPrice && c.price <= MaxPrice)
                           .Include(s => s.Sizes)
                           .Include(c => c.Colors);
            }
        }
Example #2
0
        public async Task <ReadOnlyCollection <Recruiter> > GetAllHiringManagers(CancellationToken cancellationToken)
        {
            var result = await _recruitersIncludableGetQuery
                         .Where(x => x.Role == RecruiterRole.HiringManager)
                         .ToArrayAsync(cancellationToken);

            return(Array.AsReadOnly(result));
        }
 private void SearchByCreationDate(ref IIncludableQueryable <Order, Address> orders, DateTime?MinDate, DateTime?MaxDate)
 {
     if (MinDate == null && MaxDate != null)
     {
         orders = orders.Where(o => o.date.CompareTo(MaxDate.Value) <= 0).Include(o => o.Address);
     }
     else if (MinDate != null && MaxDate == null)
     {
         orders = orders.Where(o => o.date.CompareTo(MinDate.Value) >= 0).Include(o => o.Address);
     }
     else if (MinDate != null && MaxDate != null)
     {
         orders = orders.Where(o => o.date.CompareTo(MinDate.Value) >= 0 &&
                               o.date.CompareTo(MaxDate.Value) <= 0).Include(o => o.Address);
     }
 }
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var organizationsManagedByUser = _context.OrganizationAdministratorUsers
                                             .Where(x => x.User == user)
                                             .Select(x => x.OrganizationId)
                                             .ToList();

            IIncludableQueryable <Opportunity, Organization> opportunitiesQueryable = _context.Opportunities
                                                                                      .Include(o => o.Category)
                                                                                      .Include(o => o.CreatedBy)
                                                                                      .Include(o => o.Organization);

            List <Opportunity> opportunities = opportunitiesQueryable
                                               .Where(x => organizationsManagedByUser.Contains(x.Organization.Id))
                                               .OrderByDescending(x => x.Id)
                                               .ToList();

            return(View(opportunities
                        .Select(opportunity => new OpportunityIndexViewModel()
            {
                Id = opportunity.Id,
                CreatedDateTime = opportunity.CreatedDateTime,
                Name = opportunity.Name,
                Category = opportunity.Category?.Name,
                OpportunityType = opportunity.OpportunityType,
                IsArchived = opportunity.IsArchived
            })
                        .ToList()));
        }
Example #5
0
        private void UpdatePaymentStatus(IIncludableQueryable <Member, ICollection <Change> > members, QParaOptions options, ILogger log)
        {
            this.ChangeTracker.AutoDetectChangesEnabled = false;
            var selectedMembers = members
                                  .Where(x => x.SubscriptionPeriod != SubscriptionPeriod.Life &&
                                         (x.SubscriptionType == SubscriptionType.Standard || x.SubscriptionType == SubscriptionType.Concession))
            ;
            var notSelectedMembers = members.Except(selectedMembers).Where(x => !x.GetIsPaid(options) /*!x.IsPaid*/);

            foreach (var m in notSelectedMembers.ToArray())
            {
                if (m.AmountDue != 0 || m.AmountReceived != 0)
                {
                    m.AmountDue = m.AmountReceived = 0;
                    log.Information($"{m.FirstName} {m.LastName} due and received amounts reset (to 0)");
                    //SaveChanges();
                }
            }
            var subscriptionYear = options.GetSubscriptionYear(DateTimeOffset.UtcNow);

            foreach (var m in selectedMembers.ToArray())
            {
                m.UpdatePaymentRecords(options, true);
                //SaveChanges();
            }
            ChangeTracker.DetectChanges();
            SaveChanges();
            this.ChangeTracker.AutoDetectChangesEnabled = true;
        }
Example #6
0
        public async Task <ReadOnlyCollection <Candidate> > Search(string searchText, int maxResults, CancellationToken cancellationToken = default)
        {
            Candidate[] candidates;

            if (!string.IsNullOrEmpty(searchText))
            {
                if (int.TryParse(searchText, out var id))
                {
                    var candidate = await GetById(id, cancellationToken);

                    candidates = new[] { candidate };
                }
                else
                {
                    candidates = await _candidatesIncludableGetQuery
                                 .Where(x => x.Name.ToLowerInvariant().Contains(searchText.ToLowerInvariant()))
                                 .Take(maxResults)
                                 .ToArrayAsync(cancellationToken);
                }
            }
            else
            {
                candidates = await _candidatesIncludableGetQuery
                             .Take(maxResults)
                             .ToArrayAsync(cancellationToken);
            }

            return(Array.AsReadOnly(candidates));
        }
        public async Task <IActionResult> Index()
        {
            ApplicationUser user = await GetCurrentUser();

            bool isAdmin = await IsAdmin(user);

            IIncludableQueryable <Opportunity, Organization> opportunitiesQueryable = _context.Opportunities
                                                                                      .Include(o => o.Category)
                                                                                      .Include(o => o.Community)
                                                                                      .Include(o => o.Organization);

            List <Opportunity> opportunities;

            if (isAdmin)
            {
                opportunities = await opportunitiesQueryable
                                .ToListAsync();
            }
            else
            {
                opportunities = await opportunitiesQueryable
                                .Where(o => o.CreatedByUserId == user.Id)
                                .ToListAsync();
            }

            return(View(opportunities));
        }
Example #8
0
        public IActionResult Filter(int?company, string name)
        {
            IIncludableQueryable <MetanitExampleCoreMVC.Models.User, Company> users = dbUsers.Users.Include(p => p.Company);
            IQueryable <MetanitExampleCoreMVC.Models.User> usersResult = null;

            if (company != null && company != 0)
            {
                usersResult = users.Where(p => p.CompanyId == company);
            }
            else
            {
                usersResult = users;
            }

            if (!String.IsNullOrEmpty(name))
            {
                usersResult = usersResult.Where(p => p.Name.Contains(name));
            }

            List <Company> companies = dbUsers.Companies.ToList();

            // устанавливаем начальный элемент, который позволит выбрать всех
            companies.Insert(0, new Company {
                Name = "Все", Id = 0
            });

            UsersListViewModel viewModel = new UsersListViewModel
            {
                Users     = usersResult?.ToList(),
                Companies = new SelectList(companies, "Id", "Name"),
                Name      = name
            };

            return(View(viewModel));
        }
 public void SearchByZip(ref IIncludableQueryable <Order, Address> orders, string zip)
 {
     if (!orders.Any() || string.IsNullOrEmpty(zip))
     {
         return;
     }
     orders = orders.Where(o => o.zip.Contains(zip.Trim())).Include(o => o.Address);
 }
 public void SearchByCountry(ref IIncludableQueryable <Order, Address> orders, string country)
 {
     if (!orders.Any() || string.IsNullOrEmpty(country))
     {
         return;
     }
     orders = orders.Where(o => o.country.Contains(country.Trim().ToLower())).Include(o => o.Address);
 }
 private void SearchByCustomer(ref IIncludableQueryable <Order, Address> orders, int?customerId)
 {
     if (!orders.Any() || customerId == null)
     {
         return;
     }
     orders = orders.Where(o => o.customerId == customerId).Include(o => o.Address);
 }
 public void SearchByState(ref IIncludableQueryable <Order, Address> orders, string state)
 {
     if (!orders.Any() || string.IsNullOrEmpty(state))
     {
         return;
     }
     orders = orders.Where(o => o.state.Contains(state.Trim().ToLower()))
              .Include(o => o.Address);
 }
 public void SearchByOrderNumber(ref IIncludableQueryable <Order, Address> orders, string orderNumber)
 {
     if (!orders.Any() || string.IsNullOrEmpty(orderNumber))
     {
         return;
     }
     orders = orders.Where(o => o.orderNumber.ToLower().Contains(orderNumber.Trim().ToLower()))
              .Include(o => o.Address);
 }
Example #14
0
 private void RemoveExtraneousMembers(IIncludableQueryable <Member, ICollection <Change> > members, ILogger log)
 {
     foreach (var m in members.Where(x => x.FirstName.StartsWith("(") && x.FirstName.EndsWith(")")).ToArray())
     {
         Delete(m);
         this.SaveChanges();
         log.Information($"delete member {m.Name}?");
     }
 }
 public void SearchByAddress2(ref IIncludableQueryable <Order, Address> orders, string address2)
 {
     if (!orders.Any() || string.IsNullOrEmpty(address2))
     {
         return;
     }
     orders = orders.Where(o => o.Address.address2.Contains(address2.Trim().ToLower()) ||
                           o.address2.Contains(address2.Trim().ToLower()))
              .Include(o => o.Address);
 }
        private void SearchByWeight(ref IIncludableQueryable <Product, ICollection <Color> > products, double?MaxWeight)
        {
            if (!products.Any() || MaxWeight == null)
            {
                return;
            }

            products = products.Where(p => p.weight <= MaxWeight)
                       .Include(s => s.Sizes)
                       .Include(c => c.Colors);
        }
        private void SearchBySKU(ref IIncludableQueryable <Product, ICollection <Color> > products, string sku)
        {
            if (!products.Any() || string.IsNullOrWhiteSpace(sku))
            {
                return;
            }

            products = products.Where(p => p.sku.ToLower().Contains(sku.Trim().ToLower()))
                       .Include(s => s.Sizes)
                       .Include(c => c.Colors);
        }
        private void SearchByCategoryId(ref IIncludableQueryable <Product, ICollection <Color> > products, int?categoryId)
        {
            if (!products.Any() || categoryId == null)
            {
                return;
            }

            products = products.Where(p => p.categoryId == categoryId)
                       .Include(s => s.Sizes)
                       .Include(c => c.Colors);
        }
        private void SearchByArchive(ref IIncludableQueryable <Product, ICollection <Color> > products, bool?archive)
        {
            if (!products.Any() || archive == null)
            {
                return;
            }

            products = products.Where(p => p.archive == archive)
                       .Include(s => s.Sizes)
                       .Include(c => c.Colors);
        }
        private void SearchByStock(ref IIncludableQueryable <Product, ICollection <Color> > products, double?MaxStock)
        {
            if (!products.Any() || MaxStock == null)
            {
                return;
            }

            products = products.Where(p => p.stock <= MaxStock)
                       .Include(s => s.Sizes)
                       .Include(c => c.Colors);
        }
Example #21
0
        private static async Task Main(string[] args)
        {
            var context = new TestContext();

            const string SSN       = "1337080919";
            var          newPerson = new Person
            {
                SSN         = SSN,
                FirstName   = "HTL",
                LastName    = "Student",
                DateOfBirth = new DateTime(2019, 09, 08),
                IsAwesome   = true,
                Awesomeness = 6.77,
                Addresses   = new List <Address>
                {
                    new Address
                    {
                        SSN       = SSN,
                        AddressNo = 1,
                        Country   = "Austria",
                        City      = "Leonding",
                        Street    = "Limesstr.",
                        StreetNo  = 12
                    }
                }
            };
            await context.Person.AddAsync(newPerson);

            await context.SaveChangesAsync();

            IIncludableQueryable <Person, List <Address> > src = context.Person.Include(p => p.Addresses);
            List <string> queryRes1 = await src
                                      .Where(p => p.IsAwesome)
                                      .SelectMany(p => p.Addresses)
                                      .Select(a => a.City)
                                      .Distinct()
                                      .OrderBy(n => n)
                                      .ToListAsync();

            Dictionary <bool, int> queryRes2 = await src
                                               .GroupBy(p => p.IsAwesome)
                                               .Select(g => new { Awesome = g.Key, Count = g.Count() })
                                               .ToDictionaryAsync(t => t.Awesome, t => t.Count);

            Console.WriteLine("Cities with awesome people:");
            foreach (string city in queryRes1)
            {
                Console.WriteLine(city);
            }

            Console.WriteLine(
                $"{Environment.NewLine}In total there are {queryRes2[true]} awesome and {queryRes2[false]} not awesome people");
        }
        private void SearchByShippingPrice(ref IIncludableQueryable <Order, Address> orders, double?MinPrice, double?MaxPrice)
        {
            if (!orders.Any())
            {
                return;
            }

            if (MinPrice == null && MaxPrice != null)
            {
                orders = orders.Where(o => o.shipping <= MaxPrice).Include(o => o.Address);
            }
            else if (MinPrice != null && MaxPrice == null)
            {
                orders = orders.Where(o => o.shipping >= MinPrice).Include(o => o.Address);
            }
            else if (MinPrice != null && MaxPrice != null)
            {
                orders = orders.Where(o => o.shipping >= MinPrice && o.shipping <= MaxPrice)
                         .Include(o => o.Address);
            }
        }
        private void SearchByTotalPrice(ref IIncludableQueryable <Order, Address> orders, double?MinTotal, double?MaxTotal)
        {
            if (!orders.Any())
            {
                return;
            }

            if (MinTotal == null && MaxTotal != null)
            {
                orders = orders.Where(o => o.total <= MaxTotal).Include(o => o.Address);
            }
            else if (MinTotal != null && MaxTotal == null)
            {
                orders = orders.Where(o => o.total >= MinTotal).Include(o => o.Address);
            }
            else if (MinTotal != null && MaxTotal != null)
            {
                orders = orders.Where(o => o.total >= MinTotal && o.total <= MaxTotal)
                         .Include(o => o.Address);
            }
        }
        public async Task <ReadOnlyCollection <Position> > Search(string searchText, int maxResults, CancellationToken cancellationToken)
        {
            Position[] positions;
            if (string.IsNullOrEmpty(searchText))
            {
                positions = await _positionsIncludableGetQuery
                            .OrderBy(x => x.DaysOpen)
                            .Take(maxResults)
                            .ToArrayAsync(cancellationToken);
            }
            else
            {
                searchText = searchText.ToLowerInvariant();

                positions = await _positionsIncludableGetQuery
                            .Where(x => x.Title.ToLowerInvariant().Contains(searchText) ||
                                   x.PositionExternalId.ToLowerInvariant().Contains(searchText))
                            .OrderBy(x => x.DaysOpen)
                            .Take(maxResults)
                            .ToArrayAsync(cancellationToken);
            }

            return(Array.AsReadOnly(positions));
        }
Example #25
0
        private void ConvertPaymentsToSubscriptionYears(IIncludableQueryable <Member, ICollection <Change> > members, ILogger log)
        {
            this.ChangeTracker.AutoDetectChangesEnabled = false;
            var selectedMembers = members.Where(x => x.Payments.Count() > 0 && x.Payments.Any(p => string.IsNullOrWhiteSpace(p.SubscriptionYear)));

            foreach (var m in selectedMembers.ToArray())
            {
                foreach (var payment in m.Payments.ToArray())
                {
                    var year = payment.DueDate.Year;
                    //var month = payment.DueDate.Month;
                    var subscriptionYear = $"{year}/{(year + 1) % 2000}";
                    payment.SubscriptionYear = subscriptionYear;
                }
                log.Information($"{m.FirstName} {m.LastName} subscription years updated");
                //SaveChanges();
            }
            this.ChangeTracker.DetectChanges();
            this.SaveChanges();
            this.ChangeTracker.AutoDetectChangesEnabled = true;
        }
Example #26
0
        // [Authorize(oAppConst.AccessPolicies.LevelTwo)] /// Done
        public async Task <IActionResult> Get(
            int selectedPage,
            int maxNumberPerItemsPage,
            int filterProductStoreId,
            string filterProductCategory,
            string searchValue       = "",
            string filterProductUnit = "",
            string filterStatus      = "",
            bool isAccendingSort     = true,
            SortByType sortByType    = SortByType.product)
        {
            try
            {
                bool.TryParse(filterStatus, out bool boolFilterStatus);
                int.TryParse(filterProductCategory, out int filterProductCategoryId);
                ProductUnitType productUnitType = ProductUnitType.Grams;
                switch (filterProductUnit)
                {
                case nameof(ProductUnitType.Grams):
                    productUnitType = ProductUnitType.Grams;
                    break;

                case nameof(ProductUnitType.Kg):
                    productUnitType = ProductUnitType.Kg;
                    break;

                case nameof(ProductUnitType.PerItem):
                    productUnitType = ProductUnitType.PerItem;
                    break;

                default:
                    filterProductUnit = oAppConst.GetAllRecords;
                    break;
                }
                int totalCount = await DbContext.StoreProducts
                                 .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                 .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                 .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                 .CountAsync(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                 .ConfigureAwait(false);

                /// Include the necessary properties
                IIncludableQueryable <oStoreProduct, oCategory> product = DbContext.StoreProducts
                                                                          .Include(sp => sp.Store)
                                                                          .Include(sp => sp.Product)
                                                                          .ThenInclude(p => p.Category);

                IQueryable sortedList;
                if (isAccendingSort)
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderBy(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderBy(sp => sp.Product.Price),
                        SortByType.unit => product.OrderBy(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderBy(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderBy(sp => sp.Status),
                        _ => product.OrderBy(sp => sp.Product.Name),
                    }
                }
                ;
                else
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderByDescending(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderByDescending(sp => sp.Product.Price),
                        SortByType.unit => product.OrderByDescending(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderByDescending(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderByDescending(sp => sp.Status),
                        _ => product.OrderByDescending(sp => sp.Product.Name),
                    }
                };

                List <oStoreProduct> list = await product
                                            .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                            .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                            .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                            .Where(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                            .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                                            .Take(maxNumberPerItemsPage)
                                            .ToListAsync()
                                            .ConfigureAwait(false);


                //int totalCount = await DbContext.Products
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .CountAsync(c => searchValue.Equals(oAppConst.GetAllRecords) ? true : c.Name.Contains(searchValue))
                //    .ConfigureAwait(false);

                //List<oProduct> list = await DbContext.Products
                //    .OrderBy(c => c.Name)
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .Include(t => t.StoreProducts)
                //    .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                //    .Take(maxNumberPerItemsPage)
                //    .ToListAsync()
                //    .ConfigureAwait(false);
                //foreach (oProduct product in list)
                //{
                //    product.StoreProducts = product.StoreProducts.Where(t => t.StoreId == filterProductStoreId).ToList();
                //}
                /// return the list of Categories
                return(Ok(new { list, totalCount }));
            }
Example #27
0
 public Task <List <Publication> > GetListForUserAsync(ApplicationUser user)
 {
     return(_publications.Where(p => p.Author == user).OrderedQueryable().ToListAsync());
 }