public void DeleteProductionJob(ProductionJobPosting jobToRemove) { ProductionJobPosting productionJob = _dbContext.ProductionJobPostings.Find(jobToRemove.HelpWantedID); if (productionJob != null) { _dbContext.ProductionJobPostings.Remove(jobToRemove); } }
public void ProductionJobService_ReadProductionJobPosting_Pass() { //Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var productionService = new ProductionService(dbcontext); var productionJobService = new ProductionJobService(dbcontext); var expected = true; var actual = false; var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); var production = new Production(theater.TheaterID, "someName", "directorln", "directorfn", "street", "city", "state", "country", "zip"); theaterService.CreateTheater(theater); productionService.CreateProduction(production); dbcontext.SaveChanges(); /* 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 jobPosting = new ProductionJobPosting((int)production.ProductionID, "intern", "some decription", "title", "hours", "some requirements"); //Act productionJobService.CreateProductionJob(jobPosting); dbcontext.SaveChanges(); ProductionJobPosting productionJobPost = productionJobService.GetProductionJob(jobPosting); if (productionJobPost != null) { actual = true; } productionJobService.DeleteProductionJob(jobPosting); productionService.DeleteProduction(production); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); //Assert Assert.AreEqual(expected, actual); }
public IHttpActionResult CreateProductionJob([FromBody] ProductionJobPosting productionJob) { using (var dbcontext = new BroadwayBuilderContext()) { ProductionJobService jobService = new ProductionJobService(dbcontext); try { if (productionJob == null) { return(Content((HttpStatusCode)404, "The job posting does not exist")); } jobService.CreateProductionJob(productionJob); var results = dbcontext.SaveChanges(); if (results > 0) { return(Content((HttpStatusCode)201, "Production Job Posting Created")); } else { throw new ZeroAffectedRowsException(); } } catch (ZeroAffectedRowsException) { return(Content((HttpStatusCode)500, "There appears to be no changes made. The job posting was not created")); } catch (DbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to created the requested job posting")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
public ProductionJobPosting GetProductionJob(ProductionJobPosting productionJob) { return(_dbContext.ProductionJobPostings.Find(productionJob.HelpWantedID)); }
public void CreateProductionJob(ProductionJobPosting productionJob) { productionJob.DateCreated = DateTime.Now; _dbContext.ProductionJobPostings.Add(productionJob); }