public IHttpActionResult deleteProductiondateTime(int productionDateTimeid, ProductionDateTime productionDateTimeToDelete) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); try { if (productionDateTimeToDelete == null) { return(BadRequest("no production date time object provided")); } productionService.DeleteProductionDateTime(productionDateTimeToDelete); dbcontext.SaveChanges(); return(Ok("Production date time deleted succesfully!")); } catch (Exception e) { // Todo: Catch a specific error so you can tell send a specific response model stating why a production date time was not able to be deleted return(BadRequest("Was not able to delete production date time because.....")); } } } catch (Exception e) { // Todo: User proper error handling responses catch a more specific error return(BadRequest("Major error happened!")); } }
public IHttpActionResult deleteProductiondateTime(int productionDateTimeid, ProductionDateTime productionDateTimeToDelete) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); if (productionDateTimeToDelete == null) { return(BadRequest("no production date time object provided")); } productionService.DeleteProductionDateTime(productionDateTimeToDelete); dbcontext.SaveChanges(); return(Ok("Production date time deleted succesfully!")); } } catch (DbUpdateException e) { return(Content((HttpStatusCode)500, e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult createProductionDateTime(int productionId, [FromBody] ProductionDateTime productionDateTime) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); try { if (productionDateTime == null) { return(BadRequest("no production date time object provided")); } productionDateTime.ProductionID = productionId; productionService.CreateProductionDateTime(productionDateTime); dbcontext.SaveChanges(); // Todo: Change this to a 201 Created(insert url of resource) once get productiondate time route is created return(Ok(productionDateTime)); } catch (Exception e) { return(BadRequest()); } } } catch (Exception e) { return(BadRequest("Something went wrong!")); } }
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 IHttpActionResult CreateProductionDateTime(int productionId, [FromBody] ProductionDateTime productionDateTime) { try { using (var dbcontext = new BroadwayBuilderContext()) { var productionService = new ProductionService(dbcontext); if (productionDateTime == null) { return(BadRequest("no production date time object provided")); } productionDateTime.ProductionID = productionId; productionService.CreateProductionDateTime(productionId, productionDateTime); dbcontext.SaveChanges(); return(Ok("Production Date and time have been added!")); } } catch (DbUpdateException e) { return(Content((HttpStatusCode)500, e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void ProductionController_CreateProductionDateTime_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "Some Theater 1", StreetAddress = "Theater St", State = "CA", City = "LA", CompanyName = "Regal", Country = "US", PhoneNumber = "123456789" }; theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var production = new Production() { ProductionName = "The Lion King 2", DirectorFirstName = "Jane", DirectorLastName = "Doe", Street = "Anahiem", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; var productionService = new ProductionService(dbcontext); productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/23/2019 3:22:29 PM"); var time = TimeSpan.Parse("10:30:00"); var productionDateTime = new ProductionDateTime(production.ProductionID, date, time); var productionController = new ProductionController(); // Act var actionResult = productionController.CreateProductionDateTime(production.ProductionID, productionDateTime); var response = actionResult as OkNegotiatedContentResult <string>; productionService.DeleteProductionDateTime(productionDateTime); dbcontext.SaveChanges(); productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual("Production Date and time have been added!", response.Content); }
public void CreateProductionDateTime(int productionId, ProductionDateTime productionDateTime) { if (!_dbContext.Productions.Where(o => o.ProductionID == productionId).Any()) { throw new ProductionNotFoundException($"Production does not exist! with id: {productionId}"); } _dbContext.ProductionDateTimes.Add(productionDateTime); }
public void ProductionService_CreateProductionDateTime_Pass() { //Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater("The Magicians", "Regal", "theater st", "LA", "CA", "US", "323323"); theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var productionService = new ProductionService(dbcontext); var productionName = "The Lion King"; var directorFirstName = "Joan"; var directorLastName = "Doe"; var street = "123 Anahiem St"; var city = "Long Beach"; var stateProvince = "California"; var country = "United States"; var zipcode = "919293"; var production = new Production(theater.TheaterID, productionName, directorFirstName, directorLastName, street, city, stateProvince, country, zipcode); productionService.CreateProduction(production); dbcontext.SaveChanges(); var date = DateTime.Parse("3/23/2019 3:22:29 PM"); var time = TimeSpan.Parse("10:30:00"); /* Info: Had to cast to int because in production entity model int was made into a Nullable<int> or int? for data validation purposes * If we make model in frontend then we can remove this cast to int and it will make things cleaner */ var productionDateTime = new ProductionDateTime((int)production.ProductionID, date, time); var expected = true; var actual = false; // Act productionService.CreateProductionDateTime(productionDateTime); dbcontext.SaveChanges(); if (productionDateTime.ProductionDateTimeId > 0) { actual = true; } // Assert productionService.DeleteProduction(production); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected, actual); }
public void DeleteProductionDateTime(ProductionDateTime productionDateTime) { ProductionDateTime productionDateTimeToDelete = _dbContext.ProductionDateTimes .Where(o => o.ProductionDateTimeId == productionDateTime.ProductionDateTimeId) .FirstOrDefault();//gives you first production date time that satisfies the where if (productionDateTimeToDelete != null) { _dbContext.ProductionDateTimes.Remove(productionDateTimeToDelete); } else { throw new ProductionDateTimeNotFoundException($"Production Date Time does not exist! with ID: {productionDateTime.ProductionDateTimeId}"); } }
public ProductionDateTime UpdateProductionDateTime(ProductionDateTime productionDateTime) { ProductionDateTime currentProductionDateTime = _dbContext.ProductionDateTimes .Where(prodDateTime => prodDateTime.ProductionDateTimeId == productionDateTime.ProductionDateTimeId) .FirstOrDefault(); if (currentProductionDateTime != null) { currentProductionDateTime.Date = productionDateTime.Date; currentProductionDateTime.Time = productionDateTime.Time; } else { throw new ProductionDateTimeNotFoundException($"Production Date Time does not exist! with ID: {productionDateTime.ProductionDateTimeId}"); } return(currentProductionDateTime); }
public void DeleteProductionDateTime(ProductionDateTime productionDateTime) { ProductionDateTime productionDateTimeToDelete = _dbContext.ProductionDateTimes .Where(o => o.ProductionDateTimeId == productionDateTime.ProductionDateTimeId) .FirstOrDefault();//gives you first production date time that satisfies the where //if item doesn't exist it returns null Todo: throw a specific exception // If the production date time found is not null, delete the production if (productionDateTimeToDelete != null) { _dbContext.ProductionDateTimes.Remove(productionDateTimeToDelete); } else { //throw an exception } }
public ProductionDateTime UpdateProductionDateTime(ProductionDateTime productionDateTime) { ProductionDateTime currentProductionDateTime = _dbContext.ProductionDateTimes .Where(prodDateTime => prodDateTime.ProductionDateTimeId == productionDateTime.ProductionDateTimeId) .FirstOrDefault(); if (currentProductionDateTime != null) { currentProductionDateTime.Date = productionDateTime.Date; currentProductionDateTime.Time = productionDateTime.Time; } else { //throw an exception } return(currentProductionDateTime); }
public void ProductionService_DeleteProductionDateTime_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(); var expected = true; var actual = false; // Act productionService.DeleteProductionDateTime(productionDateTime); var affectedRows = dbcontext.SaveChanges(); if (affectedRows > 0) { actual = true; } // Assert productionService.DeleteProduction(production.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected, actual); }
public void ProductionService_GetProductionsByCurrentDate_Pass() { // Arrange // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "The Language", 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 production1 = new Production() { ProductionName = "The Lion King 14", DirectorFirstName = "Joan", DirectorLastName = "Doe", Street = "123 Anahiem St", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; productionService.CreateProduction(production1); dbcontext.SaveChanges(); var production2 = new Production() { ProductionName = "The Lion King 15", DirectorFirstName = "Joan", DirectorLastName = "Doe", Street = "123 Anahiem St", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; productionService.CreateProduction(production2); dbcontext.SaveChanges(); var productionDateTime1 = new ProductionDateTime() { Date = DateTime.Parse("3/23/2019 3:22:29 PM"), Time = TimeSpan.Parse("10:30:00"), ProductionID = production1.ProductionID }; productionService.CreateProductionDateTime(production1.ProductionID, productionDateTime1); dbcontext.SaveChanges(); var productionDateTime2 = new ProductionDateTime() { Date = DateTime.Parse("3/29/2019 3:22:29 PM"), Time = TimeSpan.Parse("5:30:00"), ProductionID = production2.ProductionID }; productionService.CreateProductionDateTime(production2.ProductionID, productionDateTime2); dbcontext.SaveChanges(); var expected = true; var actual = false; // Act var readProductionsList = productionService.GetProductionsByCurrentAndFutureDate(new DateTime(2019, 3, 1), null, 1, 10); // Theater id is meant to be null if (readProductionsList != null) { actual = true; } // Assert productionService.DeleteProductionDateTime(productionDateTime2); dbcontext.SaveChanges(); productionService.DeleteProductionDateTime(productionDateTime1); dbcontext.SaveChanges(); productionService.DeleteProduction(production1.ProductionID); dbcontext.SaveChanges(); productionService.DeleteProduction(production2.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); Assert.AreEqual(expected, actual); }
public void ProductionController_DeleteProductionDateTime_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(); var productionController = new ProductionController(); // Act var actionResult = productionController.deleteProductiondateTime(productionDateTime.ProductionDateTimeId, productionDateTime); var response = actionResult as OkNegotiatedContentResult <string>; var dbcontext_ = new BroadwayBuilderContext(); var theaterService_ = new TheaterService(dbcontext_); var theater_ = theaterService.GetTheaterByID(theater.TheaterID); theaterService_.DeleteTheater(theater_); dbcontext_.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual("Production date time deleted succesfully!", response.Content); }
public void ProductionController_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"); var productionController = new ProductionController(); // Act var actionResult = productionController.updateProductionDateTime(productionDateTime.ProductionDateTimeId, productionDateTime); var response = actionResult as OkNegotiatedContentResult <ProductionDateTime>; var updatedProductionDateTime = response.Content; var expected = new { DateTime = DateTime.Parse("3/27/2019 3:22:29 PM"), TimeSpan = TimeSpan.Parse("9:30:00") }; var actual = updatedProductionDateTime; productionService.DeleteProductionDateTime(productionDateTime); dbcontext.SaveChanges(); productionService.DeleteProduction(response.Content.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual(productionDateTime.ProductionDateTimeId, updatedProductionDateTime.ProductionDateTimeId); Assert.AreEqual(expected.DateTime, actual.Date); Assert.AreEqual(expected.TimeSpan, actual.Time); }
public void ProductionController_GetProductions_Pass() { // Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater() { TheaterName = "Some Theater", StreetAddress = "Theater St", State = "CA", City = "LA", CompanyName = "Regal", Country = "US", PhoneNumber = "123456789" }; theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var productionService = new ProductionService(dbcontext); var production1 = new Production() { ProductionName = "The Lion King 14", DirectorFirstName = "Joan", DirectorLastName = "Doe", Street = "123 Anahiem St", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; productionService.CreateProduction(production1); dbcontext.SaveChanges(); var production2 = new Production() { ProductionName = "The Lion King 15", DirectorFirstName = "Joan", DirectorLastName = "Doe", Street = "123 Anahiem St", City = "Long Beach", StateProvince = "California", Country = "United States", Zipcode = "919293", TheaterID = theater.TheaterID }; productionService.CreateProduction(production2); dbcontext.SaveChanges(); var productionDateTime1 = new ProductionDateTime() { Date = DateTime.Parse("3/23/2019 3:22:29 PM"), Time = TimeSpan.Parse("10:30:00"), ProductionID = production1.ProductionID }; productionService.CreateProductionDateTime(production1.ProductionID, productionDateTime1); dbcontext.SaveChanges(); var productionDateTime2 = new ProductionDateTime() { Date = DateTime.Parse("3/29/2019 3:22:29 PM"), Time = TimeSpan.Parse("5:30:00"), ProductionID = production2.ProductionID }; productionService.CreateProductionDateTime(production2.ProductionID, productionDateTime2); dbcontext.SaveChanges(); var productionController = new ProductionController(); // Act var actionResult = productionController.GetProductions(currentDate: new DateTime(2019, 3, 1)); var response = actionResult as OkNegotiatedContentResult <List <ProductionResponseModel> >; var productions = response.Content; var expected = true; var actual = false; if (productions.Count > 0) { actual = true; } productionService.DeleteProductionDateTime(productionDateTime2); dbcontext.SaveChanges(); productionService.DeleteProductionDateTime(productionDateTime1); dbcontext.SaveChanges(); productionService.DeleteProduction(production1.ProductionID); dbcontext.SaveChanges(); productionService.DeleteProduction(production2.ProductionID); dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); // Assert Assert.IsNotNull(response.Content); Assert.AreEqual(expected, actual); }
public void CreateProductionDateTime(ProductionDateTime productionDateTime) { _dbContext.ProductionDateTimes.Add(productionDateTime); }