示例#1
0
        public async Task Add(IEnumerable <GridReference> gridReferences)
        {
            foreach (GridReference gridReference in gridReferences)
            {
                foreach (Year year in gridReference.Years)
                {
                    for (int monthIndex = 0; monthIndex < year.Months.Count; monthIndex++)
                    {
                        DateTime date = new DateTime(year.YearValue, monthIndex + 1, 1);

                        Precipitation precipitation = new Precipitation()
                        {
                            Xref  = gridReference.XRef,
                            Yref  = gridReference.YRef,
                            Date  = date.Date,
                            Value = year.Months[monthIndex]
                        };

                        await _dbContext.AddAsync(precipitation);
                    }
                }
            }

            await _dbContext.SaveChangesAsync();
        }
示例#2
0
        public async Task <int> Get(int xRef, int yRef, int year, int month)
        {
            Precipitation precipitation = await _dbContext.Precipitations
                                          .Where(p => p.Xref == xRef && p.Yref == yRef)
                                          .Where(p => p.Date.Year == year && p.Date.Month == month)
                                          .SingleOrDefaultAsync();

            if (precipitation != null)
            {
                return(precipitation.Value);
            }

            return(0);
        }