示例#1
0
        public async Task <StockEntryValue> GetStockEntryValue(int entryId)
        {
            StockEntryValue entry = await _context.StockEntryValues
                                    .FirstOrDefaultAsync(sev => sev.Id == entryId);

            return(entry);
        }
示例#2
0
        public async Task <StockEntryValue> GetOldestStockEntryValue(string barcode, int environmentId)
        {
            StockEntryValue entry = await _context.StockEntryValues
                                    .Include(sev => sev.Article)
                                    .OrderBy(sev => sev.ExpireDate)
                                    .FirstOrDefaultAsync(sev => sev.EnvironmentId == environmentId &&
                                                         sev.Article.Barcode == barcode);

            return(entry);
        }
示例#3
0
        public async Task <DateTime> GetLastExpireDate(string barcode, int environmentId)
        {
            StockEntryValue lastExpireDate = await _context.StockEntryValues
                                             .Include(sev => sev.Article)
                                             .Where(sev => sev.Article.Barcode == barcode &&
                                                    sev.EnvironmentId == environmentId)
                                             .OrderBy(sev => sev.ExpireDate).FirstOrDefaultAsync();

            return(lastExpireDate?.ExpireDate ?? DateTime.Now);
        }
示例#4
0
        public async Task <StockEntryValue> AddStockEntry(StockEntryValue entryValues, long usualLifetime)
        {
            StockEntry stockEntry = await _context.StockEntries
                                    .Include(se => se.Article).ThenInclude(a => a.ArticleUserSettings)
                                    .FirstOrDefaultAsync(se => se.EnvironmentId == entryValues.EnvironmentId &&
                                                         se.ArticleId == entryValues.ArticleId);

            if (stockEntry == null)
            {
                stockEntry = new StockEntry()
                {
                    EnvironmentId = entryValues.EnvironmentId,
                    ArticleId     = entryValues.ArticleId
                };
                await _context.StockEntries.AddAsync(stockEntry);

                await _context.StockEntryValues.AddAsync(entryValues);

                entryValues.StockEntry = stockEntry;
            }
            else
            {
                StockEntryValue existingEntryValues = await _context.StockEntryValues
                                                      .FirstOrDefaultAsync(sev => sev.ArticleId == entryValues.ArticleId &&
                                                                           sev.ExpireDate == entryValues.ExpireDate &&
                                                                           sev.EnvironmentId == entryValues.EnvironmentId &&
                                                                           sev.IsOpened == false);

                if (existingEntryValues == null)
                {
                    await _context.StockEntryValues.AddAsync(entryValues);

                    entryValues.StockEntry = stockEntry;
                }
                else
                {
                    existingEntryValues.AmountOnStock += entryValues.AmountOnStock;
                }
            }

            ArticleUserSetting articleUserSetting = await _context.ArticleUserSettings
                                                    .Include(aus => aus.Article)
                                                    .FirstOrDefaultAsync(aus => aus.Article.Id == entryValues.ArticleId);

            articleUserSetting.UsualLifetime = usualLifetime;

            await _context.SaveChangesAsync();

            return(entryValues);
        }
示例#5
0
        public async Task <bool> CreateStockEntryValue(StockEntryValue newEntry)
        {
            await _context.StockEntryValues.AddAsync(newEntry);

            return(await _context.SaveChangesAsync() > 0);
        }