public IHttpActionResult updateProductionDateTime(int productionDateTimeId, [FromBody] ProductionDateTime productionDateTime) { try { using (var dbContext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbContext); if (productionDateTime == null) { return(BadRequest("no date time was provided")); } // Set the production date time id that is to be updated to the id in the uri productionDateTime.ProductionDateTimeId = productionDateTimeId; var updatedProductionDateTime = productionService.UpdateProductionDateTime(productionDateTime); dbContext.SaveChanges(); return(Ok(updatedProductionDateTime)); } } catch (DbUpdateException e) { return(Content((HttpStatusCode)500, e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult updateProductionDateTime(int productionDateTimeId, [FromBody] ProductionDateTime productionDateTime) { try { using (var dbContext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbContext); try { if (productionDateTime == null) { return(BadRequest("no date time was provided")); } // Set the production date time id that is to be updated to the id in the uri productionDateTime.ProductionDateTimeId = productionDateTimeId; var updatedProductionDateTime = productionService.UpdateProductionDateTime(productionDateTime); dbContext.SaveChanges(); return(Ok(updatedProductionDateTime)); } catch (Exception e) { // If none of those if statements were met and we couldnt update a production... return(BadRequest()); } } } catch (Exception e) { // Todo: add proper error response when requet fails due to not being able to create dbcontext... return(BadRequest("Something bad happend!")); } }
public void ProductionService_UpdateProductionDateTime_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Magicians", StreetAddress = "Pantene", State = "CA", City = "LA", CompanyName = "123 Sesame St", Country = "US", PhoneNumber = "123456789" }; theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var productionService = new ProductionService(dbcontext); var production = new Production { ProductionName = "The Pajama Game 1", DirectorFirstName = "Doris", DirectorLastName = "Day", City = "San Diego", StateProvince = "California", Country = "U.S", TheaterID = theater.TheaterID, Street = "1234 Sesame St", Zipcode = "91911" }; productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/28/2019 3:22:29 PM"); var time = TimeSpan.Parse("11:30:00"); var productionDateTime = new ProductionDateTime(production.ProductionID, date, time); productionService.CreateProductionDateTime(production.ProductionID, productionDateTime); dbcontext.SaveChanges(); productionDateTime.Date = DateTime.Parse("3/27/2019 3:22:29 PM"); productionDateTime.Time = TimeSpan.Parse("9:30:00"); // Info: Timespan format is hh:mm:ss Ex. 09:30:00 var expected = new { DateTime = DateTime.Parse("3/27/2019 3:22:29 PM"), TimeSpan = TimeSpan.Parse("9:30:00") }; // Act var actual = productionService.UpdateProductionDateTime(productionDateTime); dbcontext.SaveChanges(); // Assert productionService.DeleteProductionDateTime(productionDateTime); dbcontext.SaveChanges(); productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected.DateTime, actual.Date); Assert.AreEqual(expected.TimeSpan, actual.Time); }