Пример #1
0
 public async Task <CurrencyModel> GetCurrency(int currencyId)
 {
     using (var context = DataContextFactory.CreateContext())
     {
         return(await context.Currency.Select(MapCurrency).FirstOrDefaultNoLockAsync(c => c.Id == currencyId));
     }
 }
Пример #2
0
        public ProductBaseModel GetProductBaseModel(int productBaseId)
        {
            if (productBaseId == 0)
            {
                return(new ProductBaseModel());
            }

            using (var context = _contextFactory.CreateContext())
            {
                var model = context.ProductBases
                            .AsNoTracking()
                            .Where(p => p.ProductBaseId == productBaseId)
                            .Include(pb => pb.Products).ThenInclude(p => p.Prices)
                            .Include(pb => pb.Products).ThenInclude(p => p.ProductSource)
                            .Include(pb => pb.Products).ThenInclude(p => p.ProductDestination)
                            .Include(pb => pb.ProductVariationsLink).ThenInclude(pvl => pvl.ProductVariation)
                            .Select(p => MappingFactory.MapTo <ProductBaseModel>(p))
                            .FirstOrDefault();

                var priceList = context.PriceLists
                                .AsNoTracking()
                                .Where(pl => pl.Prices.Any(p => p.Product.ProductBaseId == productBaseId))
                                .Select(pl => MappingFactory.MapTo <PriceListModel>(pl));

                model.PriceLists = new ObservableCollection <PriceListModel>(priceList);

                return(model);
            }
        }
Пример #3
0
 public async Task <TradePairModel> GetTradePair(int tradePairId)
 {
     using (var context = DataContextFactory.CreateContext())
     {
         return(await context.TradePair
                .Where(t => t.Currency1.IsEnabled && t.Currency2.IsEnabled)
                .Include(t => t.Currency1)
                .Include(t => t.Currency2)
                .Select(MapTradePair)
                .FirstOrDefaultNoLockAsync(t => t.Id == tradePairId));
     }
 }
Пример #4
0
 public IList <LocationInventoryListModel> GetLocationInventoryListModels(LocationInventoryListOptionModel options)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.Inventory
                .AsNoTracking()
                .FilterBy(options)
                .OrderBy(i => i.Product.ProductCode)
                .ProjectBetween <Inventory, LocationInventoryListModel>()
                .ToList());
     }
 }
Пример #5
0
        public async void InitializeAsync()
        {
            using (var context = _contextFactory.CreateContext())
            {
                BusinessLines = await GetBusinessLinesAsync(context);

                ProductSourceTypes = await GetProductSourceTypesAsync(context);

                ProductDestinationTypes = await GetProductDestinationTypesAsync(context);

                ProductStatuses = await GetProductStatusesAsync(context);

                ProductMaterials = await GetProductMaterialsAsync(context);

                ProductTypes = await GetProductTypesAsync(context);

                ProductGroups = await GetProductGroupsAsync(context);

                ProductBrands = await GetProductBrandsAsync(context);

                ProductCollections = await GetProductCollectionsAsync(context);

                ProductDesigns = await GetProductDesignsAsync(context);

                ProductSourceCompanies = await GetProductSourceCompanies(context);

                ProductDestCompanies = await GetProductDestCompanies(context);

                PriceLists = await GetPriceListsAsync(context);
            }
        }
Пример #6
0
 public SalesOrderModel GetSalesOrderModel(int salesOrderId)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.SalesOrders
                .AsNoTracking()
                .Where(s => s.SalesOrderId == salesOrderId)
                .ProjectBetween <SalesOrder, SalesOrderModel>()
                .FirstOrDefault());
     }
 }
Пример #7
0
 public DeliveryNoteModel GetDeliveryNoteModel(int deliveryHeaderId)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.DeliveryHeaders
                .AsNoTracking()
                .Where(d => d.DeliveryHeaderId == deliveryHeaderId)
                .ProjectBetween <DeliveryHeader, DeliveryNoteModel>()
                .FirstOrDefault());
     }
 }
Пример #8
0
        public async void InitializeAsync()
        {
            using (var context = _contextFactory.CreateContext())
            {
                LocationTypes = await GetLocationTypesAsync(context);

                Locations = await GetLocationsAsync(context);

                DocumentStates = GetDocumentStates();
            }
        }
Пример #9
0
 public IList <CompanyListModel> GetCompanyListModels(string query)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.Companies
                .AsNoTracking()
                .FilterBy(query)
                .OrderBy(c => c.Name)
                .ProjectBetween <Company, CompanyListModel>()
                .ToList());
     }
 }
Пример #10
0
 public IList <ProductListModel> GetProductListModels(ProductListOptionsModel options)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.ProductBases
                .AsNoTracking()
                .FilterBy(options)
                .OrderBy(p => p.ProductBaseCode)
                .ProjectBetween <ProductBase, ProductListModel>()
                .ToList());
     }
 }
Пример #11
0
 public IList <DeliveryNoteListModel> GetDeliveryNoteListModels(DeliveryNoteListOptionsModel options)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.DeliveryHeaders
                .AsNoTracking()
                .FilterBy(options)
                .OrderByDescending(d => d.DocDate)
                .ProjectBetween <DeliveryHeader, DeliveryNoteListModel>()
                .ToList());
     }
 }
Пример #12
0
 public IList <SalesOrderListModel> GetSalesOrderListModels(SalesOrderListOptionsModel options)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.SalesOrders
                .AsNoTracking()
                .FilterBy(options)
                .OrderByDescending(s => s.OrderNo)
                .ProjectBetween <SalesOrder, SalesOrderListModel>()
                .ToList());
     }
 }
Пример #13
0
 public IList <LocationListModel> GetLocationListModels(int locationTypeId)
 {
     using (var context = _contextFactory.CreateContext())
     {
         return(context.Locations
                .AsNoTracking()
                .Where(l => l.LocationTypeId == locationTypeId)
                .OrderBy(l => l.LocationName)
                .Select(l => new LocationListModel
         {
             LocationId = l.LocationId,
             LocationName = l.LocationName,
             TotalReservedQuantity = l.Inventory.Sum(i => i.ReservedQuantity),
             TotalStockQuantity = l.Inventory.Sum(i => i.StockQuantity)
         })
                .ToList());
     }
 }
Пример #14
0
        public async void InitializeAsync()
        {
            using (var context = _contextFactory.CreateContext())
            {
                Countries = await GetCountriesAsync(context);

                DocumentStates = GetDocumentStates();
                Customers      = await GetCustomersAsync(context);

                Locations = await GetLocationsAsync(context);

                PriceLists = await GetPriceListsAsync(context);

                DeliveryTerms = await GetDeliveryTermsAsync(context);

                PaymentTerms = await GetPaymentTermsAsync(context);
            }
        }
Пример #15
0
        public async void InitializeAsync()
        {
            using (var context = _contextFactory.CreateContext())
            {
                Countries = await GetCountriesAsync(context);

                Currencies = await GetCurrenciesAsync(context);

                PriceLists = await GetPriceListsAsync(context);

                Locations = await GetLocationsAsync(context);

                DeliveryTerms = await GetDeliveryTermsAsync(context);

                PaymentTerms = await GetPaymentTermsAsync(context);

                CompanyTypes = await GetCompanyTypesAsync(context);
            }
        }
Пример #16
0
        public static async Task <bool> UpdateGameStatus(int gameId, GameStatus status)
        {
            try
            {
                Log.Message(LogLevel.Info, $"[UpdateGameStatus] - Updating game status, GameId: {gameId}, Status: {status}");
                using (var context = DataContextFactory.CreateContext())
                {
                    var game = await context.Games.FirstOrDefaultAsync(x => x.Id == gameId);

                    if (game == null)
                    {
                        return(false);
                    }

                    if (status == GameStatus.Finished && game.Type == GameType.TeamBattle)
                    {
                        var result = 1;
                        var teams  = await context.Team
                                     .Where(x => x.GameId == game.Id)
                                     .OrderByDescending(x => x.Pixels.Count)
                                     .ThenBy(x => x.Name)
                                     .ToListAsync();

                        foreach (var team in teams)
                        {
                            team.Result = result;
                            result++;
                        }
                    }

                    game.Status = status;
                    await context.SaveChangesAsync();

                    Log.Message(LogLevel.Info, "[UpdateGameStatus] - Updating game status award complete.");
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Message(LogLevel.Error, $"[UpdateGameStatus] - Exception updating game status, Error: {ex.Message}");
            }
            return(false);
        }
Пример #17
0
        private async Task ProcessEmails()
        {
            Log.Message(LogLevel.Info, "[ProcessEmails] - ProcessEmails started...");
            using (var context = _dataContextFactory.CreateContext())
            {
                var templates = await context.EmailTemplate
                                .Where(x => x.IsEnabled)
                                .ToListAsync();

                var emails = await context.EmailOutbox
                             .Where(x => x.Status == EmailStatus.Pending)
                             .ToListAsync();

                if (emails.IsNullOrEmpty())
                {
                    Log.Message(LogLevel.Info, "[ProcessEmails] - No pending emails found.");
                    return;
                }

                Log.Message(LogLevel.Info, "[ProcessEmails] - {0} pending emails found.", emails.Count);
                foreach (var email in emails)
                {
                    Log.Message(LogLevel.Info, "[ProcessEmails] - Processing email, Id: {0}.", email.Id);
                    var template = templates.FirstOrDefault(x => x.Type == email.Type && x.Culture.Equals(email.UserCulture, StringComparison.OrdinalIgnoreCase))
                                   ?? templates.FirstOrDefault(x => x.Type == email.Type && x.Culture.Equals("en-US", StringComparison.OrdinalIgnoreCase));
                    if (template == null)
                    {
                        email.Status = EmailStatus.Failed;
                        email.Error  = "Template missing.";
                    }
                    else
                    {
                        email.Status = await SendEmail(template, email);
                    }
                    email.Updated = DateTime.UtcNow;
                    await context.SaveChangesAsync();

                    Log.Message(LogLevel.Info, "[ProcessEmails] - Processed email, Id: {0}, Status: {1}", email.Id, email.Status);
                }
                Log.Message(LogLevel.Info, "[ProcessEmails] - ProcessEmails complete.");
            }
        }
Пример #18
0
        public CompanyModel GetCompanyModel(int companyId)
        {
            if (companyId == 0)
            {
                return(GetNewCompanyModel());
            }

            using (var context = _contextFactory.CreateContext())
            {
                return(context.Companies
                       .AsNoTracking()
                       .Include(c => c.Addresses)
                       .Include(c => c.Contacts)
                       .Include(c => c.CompanyTypesLink).ThenInclude(l => l.CompanyType)
                       .Where(c => c.CompanyId == companyId)
                       //.ProjectBetween<Company, CompanyModel>()
                       .Select(c => MappingFactory.MapTo <CompanyModel>(c))
                       .FirstOrDefault());
            }
        }
Пример #19
0
 protected TDataContext CreateContext <TDataContext>(Func <IDbConnection, TDataContext> createContext)
     where TDataContext : DataContext
 {
     return(_dataContextFactory.CreateContext(createContext));
 }