public async Task ShouldReturnDateRanges(string begin, string end)
        {
            var dateBegin = DateTime.Parse(begin);
            var dateEnd   = DateTime.Parse(end);
            var dateModel = new ViewDateModel {
                DateBefore = dateBegin, DateAfter = dateEnd
            };
            var dates = await _dateRep.GetDatesAsync(dateModel);

            Assert.True(dates.Length > 0, $"Expected not empty list of dates in range: {begin} - {end}");
        }
Beispiel #2
0
        public async Task Post([FromBody] ViewDateModel dateModel)
        {
            try
            {
                await _dateRep.AddAsync(dateModel);

                //var response = Request.<DateModel>(HttpStatusCode.Created, dateModel);
            }
            catch
            {
                BadRequest();
            }
        }
Beispiel #3
0
        public async Task <ActionResult <ViewDateModel[]> > GetDatesAsync([FromBody] ViewDateModel dateModel)
        {
            try
            {
                var dates = await _dateRep.GetDatesAsync(dateModel);

                return(dates);
            }
            catch
            {
                return(BadRequest());
            }
        }
Beispiel #4
0
        public async Task AddAsync(ViewDateModel dateVm)
        {
            if (dateVm == null)
            {
                throw new ArgumentNullException("dateVm");
            }
            DateModel dateModel = new DateModel {
                DateBefore = dateVm.DateBefore, DateAfter = dateVm.DateAfter
            };

            _dbContext.DateModels.Add(dateModel);
            await _dbContext.SaveChangesAsync();
        }
        public async Task ShouldAddDateRange(string dateBefore, string dateAfter)
        {
            //add some range to DB
            var dateBegin = DateTime.Parse(dateBefore);
            var dateEnd   = DateTime.Parse(dateAfter);
            var dateModel = new ViewDateModel {
                DateBefore = dateBegin, DateAfter = dateEnd
            };
            await _dateRep.AddAsync(dateModel);

            //check if it created
            var dates = await _dateRep.GetDatesAsync(dateModel);

            Assert.True(dates.Any(x => x.DateBefore == dateBegin && x.DateAfter == dateEnd), $"Expected the date range {dateBefore} - {dateAfter} be found in DB.");
        }
Beispiel #6
0
        public async Task <ViewDateModel[]> GetDatesAsync(ViewDateModel dateModel)
        {
            var dateBefore = dateModel.DateBefore;
            var dateAfter  = dateModel.DateAfter;
            var dates      = await _dbContext.Set <DateModel>()
                             .Where(x => x.DateBefore >= dateBefore && x.DateAfter <= dateAfter)
                             .Select(x => new ViewDateModel
            {
                DateBefore = x.DateBefore,
                DateAfter  = x.DateAfter
            })
                             .ToArrayAsync();

            return(dates);
        }