Example #1
0
        public virtual ActionResult Add(int companyId)
        {
            var company = _companyByIdQuery.WithCompanyId(companyId).RequestedByUserId(CurrentUserId).Execute();

            if (company == null)
            {
                ViewBag.EntityType = "Position";
                return(View(MVC.Shared.Views.EntityNotFound));
            }

            var model = new EditPositionViewModel
            {
                Company = Mapper.Map <Company, CompanySummaryViewModel>(company)
            };

            return(View(MVC.Position.Views.Edit, model));
        }
Example #2
0
        /// <summary>
        /// Adds the specified Linked In position (and associated company) to the user's current job search
        /// </summary>
        /// <param name="procParams"></param>
        /// <returns></returns>
        public ExternalPositionAddedResultViewModel Execute(AddLinkedInPositionParams procParams)
        {
            Company company;
            PositionDisplayViewModel position;

            var user = _context.Users
                       .Where(x => x.Id == procParams.RequestingUserId)
                       .Include(x => x.LinkedInOAuthData)
                       .SingleOrDefault();

            if (user == null)
            {
                throw new MJLEntityNotFoundException(typeof(User), procParams.RequestingUserId);
            }

            // Make sure we have a valid oauth token for the user
            if (!_verifyLiTokenProcess.Execute(new VerifyUserLinkedInAccessTokenParams {
                UserId = user.Id
            }).AccessTokenValid)
            {
                throw new UserHasNoValidOAuthAccessTokenException(user.Id, TokenProvider.LinkedIn);
            }

            // Retrieve the position details
            var positionDetails = GetPositionDetails(procParams.PositionId, user.LinkedInOAuthData.Token, procParams.RequestingUserId);

            if (positionDetails == null)
            {
                throw new MJLEntityNotFoundException(typeof(ExternalPositionDetailsViewModel), procParams.PositionId);
            }

            // Start a transaction to make sure all operations can be rolled back
            using (var transaction = new TransactionScope())
            {
                if (procParams.CreateNewCompany)
                {
                    // Create the new company
                    company = _createCompanyCmd.SetName(positionDetails.CompanyName)
                              .WithJobSearch(Convert.ToInt32(user.LastVisitedJobSearchId))
                              .CalledByUserId(procParams.RequestingUserId)
                              .Execute();
                }
                else
                {
                    company = _companyQuery.WithCompanyId(procParams.ExistingCompanyId)
                              .RequestedByUserId(user.Id)
                              .Execute();
                    if (company == null)
                    {
                        throw new MJLEntityNotFoundException(typeof(Company), procParams.ExistingCompanyId);
                    }
                }

                // Setup the notes field
                string notes = string.Format("Location: {1}{0}Job Type: {2}{0}Experience Level: {3}{0}Job Functions: {4}{0}",
                                             Environment.NewLine,
                                             positionDetails.Location,
                                             positionDetails.JobType,
                                             positionDetails.ExperienceLevel,
                                             positionDetails.JobFunctions);

                // Create the position
                position = _createPositionProcess.Execute(new CreatePositionParams
                {
                    RequestingUserId = procParams.RequestingUserId,
                    CompanyId        = company.Id,
                    Title            = positionDetails.Title,
                    Notes            = notes,
                    LinkedInId       = procParams.PositionId
                });

                transaction.Complete();

                return(new ExternalPositionAddedResultViewModel
                {
                    PositionId = position.Id,
                    PositionTitle = position.Title,
                    CompanyId = company.Id,
                    CompanyName = company.Name
                });
            }
        }