Example #1
0
        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);
        }
Example #2
0
        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();
        }
Example #3
0
        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 PutShouldUpdateTheaterJob()
        {
            var dbcontext         = new BroadwayBuilderContext();
            var theaterService    = new TheaterService(dbcontext);
            var theaterJobService = new TheaterJobService(dbcontext);
            //var expected = true;
            //var actual = false;

            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
            jobPosting.Description = "testing";
            var actionResult = controller.EditTheaterJob(jobPosting);
            var response     = actionResult as NegotiatedContentResult <string>;
            var content      = response.Content;

            theaterJobService.DeleteTheaterJob(jobPosting);
            theaterService.DeleteTheater(theater);
            dbcontext.SaveChanges();
            ////Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.AreEqual("Updated Job Posting", content);
            Assert.AreEqual((HttpStatusCode)202, response.StatusCode);
        }
        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 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 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));
         }
     }
 }
Example #8
0
        public void DeleteTheaterJob(TheaterJobPosting theaterJob)
        {
            TheaterJobPosting jobToRemove = _dbContext.TheaterJobPostings.Find(theaterJob.HelpWantedID);

            if (jobToRemove != null)
            {
                _dbContext.TheaterJobPostings.Remove(jobToRemove);
            }
        }
        public TheaterJobPosting GetTheaterJobPosting()
        {
            TheaterJobPosting theaterJobPosting =
                new TheaterJobPosting(this.HelpWantedID, this.Position,
                                      this.Description, this.Title, this.Hours, this.Requirements,
                                      this.JobType);

            return(theaterJobPosting);
        }
        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 void UpdateProductionJob(TheaterJobPosting updatedProductionJob, TheaterJobPosting originalProductionJob)
 {
     if (originalProductionJob != null)
     {
         originalProductionJob.Title        = updatedProductionJob.Title;
         originalProductionJob.Hours        = updatedProductionJob.Hours;
         originalProductionJob.Position     = updatedProductionJob.Position;
         originalProductionJob.Requirements = updatedProductionJob.Requirements;
         originalProductionJob.theater      = updatedProductionJob.theater;
     }
 }
 public TheaterJobResponseModel(TheaterJobPosting theaterJobPosting)
 {
     this.HelpWantedID = theaterJobPosting.HelpWantedID;
     this.TheaterID    = theaterJobPosting.TheaterID;
     this.Position     = theaterJobPosting.Position;
     this.Description  = theaterJobPosting.Description;
     this.Title        = theaterJobPosting.Title;
     this.Hours        = theaterJobPosting.Hours;
     this.Requirements = theaterJobPosting.Requirements;
     this.JobType      = theaterJobPosting.JobType;
     this.DateCreated  = theaterJobPosting.DateCreated;
 }
Example #13
0
        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));
            }
        }
Example #14
0
        public void DeleteTheaterJob(int helpWantedId)
        {
            TheaterJobPosting jobToRemove = _dbContext.TheaterJobPostings.Find(helpWantedId);

            if (jobToRemove != null)
            {
                _dbContext.TheaterJobPostings.Remove(jobToRemove);
            }
            else
            {
                throw new DbEntityNotFoundException("There is no record of the specified job posting in our records.");
            }
        }
        public void EditTheaterJob_Should_ReturnErrorMessage()
        {
            //Arrange
            var controller        = new HelpWantedController();
            TheaterJobPosting job = null;

            //Act
            var actionResult = controller.EditTheaterJob(job);
            var response     = actionResult as NegotiatedContentResult <string>;
            var content      = response.Content;

            //Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.AreEqual((HttpStatusCode)400, response.StatusCode);
        }
        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));
                }
            }
        }
Example #17
0
        public void UpdateTheaterJob(TheaterJobPosting updatedTheaterJob)
        {
            TheaterJobPosting theaterJobPostingToUpdate = _dbContext.TheaterJobPostings.Find(updatedTheaterJob.HelpWantedID);

            if (theaterJobPostingToUpdate != null)
            {
                theaterJobPostingToUpdate.Position     = updatedTheaterJob.Position;
                theaterJobPostingToUpdate.Description  = updatedTheaterJob.Description;
                theaterJobPostingToUpdate.Title        = updatedTheaterJob.Title;
                theaterJobPostingToUpdate.Hours        = updatedTheaterJob.Hours;
                theaterJobPostingToUpdate.Requirements = updatedTheaterJob.Requirements;
                theaterJobPostingToUpdate.JobType      = updatedTheaterJob.JobType;
            }
            else
            {
                throw new DbEntityNotFoundException("There is no record of the specified job posting in our records.");
            }
        }
Example #18
0
        public IHttpActionResult EditTheaterJob(TheaterJobPosting job)
        {
            using (var dbcontext = new BroadwayBuilderContext())
            {
                try
                {
                    TheaterJobService service = new TheaterJobService(dbcontext);
                    //TheaterJobPosting job = service.GetTheaterJob(helpwantedid);
                    if (job != null)
                    {
                        service.UpdateTheaterJob(job);
                        var results = dbcontext.SaveChanges();
                        if (results > 0)
                        {
                            return(Content((HttpStatusCode)202, "Updated Job Posting"));//not sure to return object or just string response
                        }

                        throw new ZeroAffectedRowsException();
                    }
                    else
                    {
                        return(Content((HttpStatusCode)500, "NO such posting exists"));//need to edit
                    }
                }
                catch (ZeroAffectedRowsException)
                {
                    return(Content((HttpStatusCode)500, "There appears to be no changes detected. The Theater Job was not updated"));
                }
                catch (DbEntityValidationException)
                {
                    return(Content((HttpStatusCode)500, "Theater Job could not be updated"));
                }
                catch (Exception e)
                {
                    return(Content((HttpStatusCode)400, e.Message));
                }
            }
        }
Example #19
0
 public IHttpActionResult DeleteTheaterJob(int helpWantedId)
 {
     using (var dbcontext = new BroadwayBuilderContext())
     {
         TheaterJobService service = new TheaterJobService(dbcontext);
         TheaterJobPosting job     = service.GetTheaterJob(helpWantedId);
         try
         {
             service.DeleteTheaterJob(job);
             if (job == null)
             {
                 return(Content((HttpStatusCode)404, "That Job Listing does not exist"));
             }
             var results = dbcontext.SaveChanges();
             if (results > 0)
             {
                 return(Content((HttpStatusCode)202, "Successfully Deleted Job Posting"));
             }
             else
             {
                 throw new ZeroAffectedRowsException();
             }
         }
         catch (ZeroAffectedRowsException)
         {
             return(Content((HttpStatusCode)500, "There appears to be no changes made in the database. The job posting wasn't deleted"));
         }
         catch (DbEntityValidationException)
         {
             return(Content((HttpStatusCode)500, "Unable to delete the job posting"));
         }
         catch (Exception e)
         {
             return(Content((HttpStatusCode)400, e.Message));
         }
     }
 }
Example #20
0
 public void CreateTheaterJob(TheaterJobPosting theaterJob)
 {
     theaterJob.DateCreated = DateTime.Now;
     _dbContext.TheaterJobPostings.Add(theaterJob);
 }
Example #21
0
 public void UpdateTheaterJob(TheaterJobPosting updatedTheaterJob)
 {
     _dbContext.Entry(updatedTheaterJob).State = EntityState.Modified;
 }
Example #22
0
 public TheaterJobPosting GetTheaterJob(TheaterJobPosting theaterJob)
 {
     return(_dbContext.TheaterJobPostings.Find(theaterJob.HelpWantedID));
 }