public void Test_DailyLogMgr_CreateDailyLog() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <HOSContext>() .UseSqlite(connection) .Options; using (var context = new HOSContext(options)) { context.Database.EnsureCreated(); } using (var context = new HOSContext(options)) { HOSTestData.LoadStateProvinceCodeTable(context); HOSTestData.LoadDutyStatusTable(context); HOSTestData.LoadDutyStatusActivityTable(context); HOSTestData.LoadCompanyTable(context); HOSTestData.LoadAppUserTable(context); HOSTestData.LoadDailyLogTable(context); HOSTestData.LoadDailyLogDetailTable(context); } using (var context = new HOSContext(options)) { IDailyLogManager logMgr = new DailyLogManager(new Repository(context)); var dailyLogModel = new DailyLogModel { LogID = 4, LogDate = new DateTime(2016, 9, 10), BeginningMileage = 963000, TruckNumber = "3082", TrailerNumber = "9225", IsSigned = false, Notes = "Dropped trailer 9225 at Whirlpool and picked up loaded trailer 9159", DriverID = 4, CreatedBy = "sysadmin", CreatedOn = new DateTime(2016, 9, 10, 8, 0, 0), UpdatedBy = "sysadmin", UpdatedOn = new DateTime(2016, 9, 10, 8, 0, 0), }; logMgr.Create(dailyLogModel); logMgr.SaveChanges(); var test = logMgr.GetDailyLog(log => log.LogID == dailyLogModel.LogID); Assert.NotNull(test); Assert.Equal(new DateTime(2016, 9, 10), test.LogDate.Date); } } finally { connection.Close(); } }
public IActionResult Create([FromBody] DailyLogModel dailyentry) { if (dailyentry == null) { return(BadRequest()); } _context.DailyLogModels.Add(dailyentry); _context.SaveChanges(); return(CreatedAtRoute("GetDailyEntry", new { id = dailyentry.Id }, dailyentry)); }
public IActionResult Update(int id, [FromBody] DailyLogModel dailyentry) { if (dailyentry == null || dailyentry.Id != id) { return(BadRequest()); } var item = _context.DailyLogModels.FirstOrDefault(i => i.Id == id); if (item == null) { return(NotFound()); } item.Entry = dailyentry.Entry; item.EntryType = dailyentry.EntryType; item.Date = dailyentry.Date; _context.DailyLogModels.Update(item); _context.SaveChanges(); return(new NoContentResult()); }