Exemplo n.º 1
0
        public IHttpActionResult ResetDataSource()
        {
            DateAndTimeOfDayContext db = new DateAndTimeOfDayContext();

            if (!db.Customers.Any())
            {
                DateTimeOffset           dateTime  = new DateTimeOffset(2014, 12, 24, 1, 2, 3, 4, new TimeSpan(-8, 0, 0));
                IEnumerable <EfCustomer> customers = Enumerable.Range(1, 5).Select(e =>
                                                                                   new EfCustomer
                {
                    Id               = e,
                    DateTime         = dateTime.AddYears(e).AddHours(e).AddMilliseconds(e).DateTime,
                    NullableDateTime = e % 2 == 0 ? (DateTime?)null : dateTime.AddHours(e * 5).AddMilliseconds(e * 5).DateTime,
                    Offset           = dateTime.AddMonths(e).AddHours(e).AddMilliseconds(e),
                    NullableOffset   = e % 3 == 0 ? (DateTimeOffset?)null : dateTime.AddDays(e).AddHours(e * 5)
                }).ToList();

                foreach (EfCustomer customer in customers)
                {
                    db.Customers.Add(customer);
                }

                db.SaveChanges();
            }

            return(Ok());
        }
        public IHttpActionResult ResetDataSource()
        {
            DateAndTimeOfDayContext db = new DateAndTimeOfDayContext();
            if (!db.Customers.Any())
            {
                DateTimeOffset dateTime = new DateTimeOffset(2014, 12, 24, 1, 2, 3, 4, new TimeSpan(-8, 0, 0));
                IEnumerable<EfCustomer> customers = Enumerable.Range(1, 5).Select(e =>
                    new EfCustomer
                    {
                        Id = e,
                        DateTime = dateTime.AddYears(e).AddHours(e).AddMilliseconds(e).DateTime,
                        NullableDateTime = e % 2 == 0 ? (DateTime?)null : dateTime.AddHours(e * 5).AddMilliseconds(e * 5).DateTime,
                        Offset = dateTime.AddMonths(e).AddHours(e).AddMilliseconds(e),
                        NullableOffset = e % 3 == 0 ? (DateTimeOffset?)null : dateTime.AddDays(e).AddHours(e * 5)
                    }).ToList();

                foreach (EfCustomer customer in customers)
                {
                    db.Customers.Add(customer);
                }

                db.SaveChanges();
            }

            return Ok();
        }