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 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 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);
        }
예제 #4
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));
            }
        }