public IHttpActionResult GetResumesforTheaterJob(int helpwantedId) { try { using (var dbContext = new BroadwayBuilderContext()) { var theaterJobService = new TheaterJobPostingService(dbContext); if (theaterJobService.GetTheaterJob(helpwantedId) == null) { return(Content((HttpStatusCode)404, "Theater job does not exist")); } var resumeTheaterJobService = new ResumeTheaterJobService(dbContext); var resumeList = resumeTheaterJobService.GetAllResumeGuidsForTheaterJob(helpwantedId); List <string> urlList = new List <string>(); foreach (Guid guid in resumeList) { string path = Path.Combine(ConfigurationManager.AppSettings["ResumeDir"], guid.ToString(), guid.ToString() + ".pdf"); if (File.Exists(path)) { string url = ConfigurationManager.AppSettings["ApiResumeDir"] + guid + "/" + guid + ".pdf"; urlList.Add(url); } } return(Content((HttpStatusCode)200, urlList)); } } catch (Exception e) { return(Content((HttpStatusCode)500, e.Message)); } }
public void TheaterJobService_DeleteTheaterJobPosting_Pass() { //Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theaterJobService = new TheaterJobPostingService(dbcontext); var expected = true; var actual = false; var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType"); //Act theaterService.CreateTheater(theater); //dbcontext.SaveChanges(); theaterJobService.CreateTheaterJob(jobPosting); dbcontext.SaveChanges(); theaterJobService.DeleteTheaterJob(jobPosting.HelpWantedID); var results = dbcontext.SaveChanges(); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); if (results > 0) { actual = true; } //Assert Assert.AreEqual(expected, actual); }
public IHttpActionResult GetTheaterJobs(int theaterId, int currentPage, int numberOfItems) { using (var dbcontext = new BroadwayBuilderContext()) { try { TheaterService theaterService = new TheaterService(dbcontext); Theater theater = theaterService.GetTheaterByID(theaterId); if (theater == null)//check if theater exists; null if there is no record in the DB { //throw new DbEntityNotFoundException("There is no record of that Theater in our database"); //use Stacktrace class then log? return(Content((HttpStatusCode)404, "There is no record of that Theater in our database")); } TheaterJobPostingService service = new TheaterJobPostingService(dbcontext); int count = 0; //variable to be used for GetAllJobsFromTheater to get the count of Theater job postings found from query var list = service.GetAllJobsFromTheater(theaterId, currentPage, numberOfItems, out count); TheaterJobResponseList theaterJobResponseList = new TheaterJobResponseList(count, list); //create a response model containing the count and List of theater jobs to reduce JSON Hijacking return(Content((HttpStatusCode)200, theaterJobResponseList)); } catch (DbEntityNotFoundException e) { return(Content((HttpStatusCode)404, e.Message)); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
public IHttpActionResult ApplyToJob([FromUri] int id, [FromUri] int helpwantedid) { try { using (var dbContext = new BroadwayBuilderContext()) { var resumeService = new ResumeService(dbContext); Resume resume = resumeService.GetResumeByUserID(id); if (resume == null)//check if user has already submitted a resume; null { return(Content((HttpStatusCode)404, "No resume on file")); } var theaterJobService = new TheaterJobPostingService(dbContext); TheaterJobPosting job = theaterJobService.GetTheaterJob(helpwantedid); if (job == null)//check if job exists { return(Content((HttpStatusCode)404, "No job on file")); } var resumeJobPosting = new ResumeTheaterJob(job.HelpWantedID, resume.ResumeID); var resumeJobService = new ResumeTheaterJobService(dbContext); resumeJobService.CreateResumeTheaterJob(resumeJobPosting); var result = dbContext.SaveChanges(); if (result > 0)//check if any rows were affected in the database { return(Content((HttpStatusCode)200, "Successfully Applied!")); } return(Content((HttpStatusCode)500, "Wasn't able to successfully apply")); } } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } }
public void DeleteShouldDeleteTheaterJob() { var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theaterJobService = new TheaterJobPostingService(dbcontext); var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType"); theaterJobService.CreateTheaterJob(jobPosting); dbcontext.SaveChanges(); var controller = new HelpWantedController(); //Act var actionResult = controller.DeleteTheaterJob(jobPosting.HelpWantedID); var response = actionResult as NegotiatedContentResult <string>; var content = response.Content; var dbcontext2 = new BroadwayBuilderContext(); var theaterService2 = new TheaterService(dbcontext2); theaterService2.DeleteTheater(theater); dbcontext2.SaveChanges(); //Assert Assert.IsNotNull(response); Assert.IsNotNull(response.Content); Assert.AreEqual((HttpStatusCode)200, response.StatusCode); }
public IHttpActionResult CreateTheaterJob([FromBody] TheaterJobPosting theaterJob) { using (var dbContext = new BroadwayBuilderContext()) { TheaterJobPostingService jobService = new TheaterJobPostingService(dbContext); try { if (theaterJob == null) { return(Content((HttpStatusCode)400, "That job posting does not exist")); } jobService.CreateTheaterJob(theaterJob); var results = dbContext.SaveChanges(); if (results <= 0) { return(Content((HttpStatusCode)500, "There appears to be no additions made. The Job posting was not created")); } TheaterJobResponseModel theaterJobResponseModel = new TheaterJobResponseModel(theaterJob); return(Content((HttpStatusCode)201, theaterJobResponseModel)); } catch (DbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to create the requested job posting")); } catch (Exception e)//needs to be updated { return(Content((HttpStatusCode)400, e.Message)); } } }
public void PostShouldAddTheaterJob()//need to update { //Arrange var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theater = new Theater("someTheater2", "Regal", "theater st", "LA", "CA", "US", "323323"); theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var controller = new HelpWantedController(); TheaterJobPosting job = new TheaterJobPosting(theater.TheaterID, "test", "test", "test", "test", "test", "testType"); //Act var actionResult = controller.CreateTheaterJob(job); var response = actionResult as NegotiatedContentResult <TheaterJobResponseModel>; var content = response.Content; //Assert Assert.IsNotNull(response); Assert.IsNotNull(response.Content); Assert.AreEqual((HttpStatusCode)201, response.StatusCode); var jobservice = new TheaterJobPostingService(dbcontext); jobservice.DeleteTheaterJob(content.HelpWantedID); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); }
public void GetShouldGetAllTheaterJobs() { var dbcontext = new BroadwayBuilderContext(); var theaterService = new TheaterService(dbcontext); var theaterJobService = new TheaterJobPostingService(dbcontext); var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); theaterService.CreateTheater(theater); dbcontext.SaveChanges(); var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType"); theaterJobService.CreateTheaterJob(jobPosting); dbcontext.SaveChanges(); //Arrange var controller = new HelpWantedController(); var currentPage = 1; var numberOfItems = 100; //Act var actionResult = controller.GetTheaterJobs(theater.TheaterID, currentPage, numberOfItems); var response = actionResult as NegotiatedContentResult <TheaterJobResponseList>; //var content = response.Content; //Assert Assert.IsNotNull(response); Assert.IsNotNull(response.Content); Assert.AreEqual((HttpStatusCode)200, response.StatusCode); theaterJobService.DeleteTheaterJob(jobPosting.HelpWantedID); theaterService.DeleteTheater(theater); dbcontext.SaveChanges(); }
public void CreateResumeTheaterJob_Should_NotCreateSameResumeTheaterJob() { //Arrange var context = new BroadwayBuilderContext(); var resumeService = new ResumeService(context); var userService = new UserService(context); var theaterService = new TheaterService(context); var theaterJobService = new TheaterJobPostingService(context); var resumeTheaterJobService = new ResumeTheaterJobService(context); var expected = true; var actual = false; var user = new User("*****@*****.**", "FN", "LN", 19, new DateTime(1994, 1, 7), "address", "LA", "CA", "USA", true, Guid.NewGuid()); userService.CreateUser(user); context.SaveChanges(); var resume = new Resume(user.UserId, Guid.NewGuid()); resumeService.CreateResume(resume); context.SaveChanges(); var theater = new Theater("someTheater", "Regal", "theater st", "LA", "CA", "US", "323323"); theaterService.CreateTheater(theater); context.SaveChanges(); var jobPosting = new TheaterJobPosting(theater.TheaterID, "intern", "some decription", "title", "hours", "some requirements", "testType"); theaterJobService.CreateTheaterJob(jobPosting); context.SaveChanges(); //Act var resumeTheaterJob = new ResumeTheaterJob(jobPosting.HelpWantedID, resume.ResumeID); resumeTheaterJobService.CreateResumeTheaterJob(resumeTheaterJob); context.SaveChanges(); try { resumeTheaterJobService.CreateResumeTheaterJob(resumeTheaterJob); } catch { actual = true; } resumeTheaterJobService.DeleteResumeTheaterJob(resumeTheaterJob); resumeService.DeleteResume(resume); theaterJobService.DeleteTheaterJob(jobPosting.HelpWantedID); userService.DeleteUser(user); theaterService.DeleteTheater(theater); context.SaveChanges(); //Assert Assert.AreEqual(expected, actual); }
public IHttpActionResult UserApplyToJob(int helpwantedid) { string token = ControllerHelper.GetTokenFromAuthorizationHeader(Request.Headers); if (token == null) { return(Unauthorized()); } int id = 0; try { using (var dbContext = new BroadwayBuilderContext()) { var userService = new UserService(dbContext); var user = userService.GetUserByToken(token); if (user == null) { return(Content(HttpStatusCode.NotFound, "User was not found within the database")); } var resumeService = new ResumeService(dbContext); id = user.UserId; Resume resume = resumeService.GetResumeByUserID(id); if (resume == null)//check if user has already submitted a resume; null { return(Content((HttpStatusCode)404, "No resume on file")); } var theaterJobService = new TheaterJobPostingService(dbContext); TheaterJobPosting job = theaterJobService.GetTheaterJob(helpwantedid); if (job == null)//check if job exists { return(Content((HttpStatusCode)404, "No job on file")); } var resumeJobPosting = new ResumeTheaterJob(job.HelpWantedID, resume.ResumeID); var resumeJobService = new ResumeTheaterJobService(dbContext); resumeJobService.CreateResumeTheaterJob(resumeJobPosting); var result = dbContext.SaveChanges(); if (result > 0)//check if any rows were affected in the database { LoggerHelper.LogUsage("Apply to Theater Job", user.UserId); return(Content((HttpStatusCode)200, "Successfully Applied!")); } return(Content((HttpStatusCode)500, "Wasn't able to successfully apply")); } } catch (Exception e) { LoggerHelper.LogError("User applying to TheaterJob", id, e); return(Content((HttpStatusCode)400, e.Message)); } }
public IHttpActionResult EditTheaterJob([FromBody] TheaterJobPosting job) { using (var dbContext = new BroadwayBuilderContext()) { try { TheaterJobPostingService service = new TheaterJobPostingService(dbContext); if (job != null) { service.UpdateTheaterJob(job); var results = dbContext.SaveChanges(); if (results > 0) { return(Content((HttpStatusCode)200, "Updated Job Posting")); } //throw new ZeroAffectedRowsException(); return(Content((HttpStatusCode)500, "There appears to be no changes detected. The Theater Job was not updated")); } else { return(Content((HttpStatusCode)400, "No such posting exists")); } } //TODO: Log errors - stacktrace, message, source, TheaterJob object catch (DbEntityNotFoundException dbEntityNotFoundException) { return(Content((HttpStatusCode)404, dbEntityNotFoundException.Message)); } catch (DbEntityValidationException dbEntityValidationException)//save was aborted because validation of the entity property values failed { return(Content((HttpStatusCode)500, "Theater Job could not be updated")); } catch (DbUpdateConcurrencyException dbUpdateConcurrencyException)//concurrency violation; row has been changed in the database since it was queried { return(Content((HttpStatusCode)500, "An Error has occurred while trying to update the requested theater job posting. Please try again.")); } catch (DbUpdateException dbUpdateException) { return(Content((HttpStatusCode)500, "Failed to update the requested theater job posting.")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
public IHttpActionResult DeleteTheaterJob(int helpWantedId) { using (var dbContext = new BroadwayBuilderContext()) { TheaterJobPostingService service = new TheaterJobPostingService(dbContext); try { service.DeleteTheaterJob(helpWantedId); var results = dbContext.SaveChanges(); if (results > 0) { return(Content((HttpStatusCode)200, "Successfully Deleted Job Posting")); } return(Content((HttpStatusCode)500, "There appears to be no changes made in the database. The job posting wasn't deleted")); } catch (DbEntityNotFoundException dbEntityNotFoundException) { return(Content((HttpStatusCode)404, dbEntityNotFoundException.Message)); } catch (DbEntityValidationException dbEntityValidationException) { return(Content((HttpStatusCode)500, "Unable to delete the job posting")); } catch (DbUpdateConcurrencyException dbUpdateConcurrencyException)//concurrency violation; row has been changed in the database since it was queried { return(Content((HttpStatusCode)500, "An Error has occurred while trying to delete the requested theater job posting. Please try again.")); } catch (DbUpdateException dbUpdateException) { return(Content((HttpStatusCode)500, "Failed to delete the requested theater job posting.")); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }
public IHttpActionResult GetFilteredTheaterJobs(int theaterId, [FromUri] string[] jobType, [FromUri] string[] position, int currentPage, int numberOfItems) { using (var dbcontext = new BroadwayBuilderContext()) { try { TheaterService theaterService = new TheaterService(dbcontext); Theater theater = theaterService.GetTheaterByID(theaterId); if (theater == null) { return(Content((HttpStatusCode)404, "There is no record of that Theater in our database")); } TheaterJobPostingService service = new TheaterJobPostingService(dbcontext); int count = 0; var list = service.FilterTheaterJobPostingsFromTheater(theaterId, jobType, position, currentPage, numberOfItems, out count); TheaterJobResponseList theaterJobResponseList = new TheaterJobResponseList(count, list); return(Content((HttpStatusCode)200, theaterJobResponseList)); } catch (Exception e) { return(Content((HttpStatusCode)400, e.Message)); } } }