Example #1
0
        /// <summary>
        /// This method creates a job with the given parameters and adds it
        /// to the database.
        /// </summary>
        /// <param name="name">The name of the job that is being created</param>
        /// <param name="salary">The monthly salary of the job</param>
        /// <param name="category">The category of the job i.e. programming, management, etc.</param>
        /// <param name="description">The description of the job so that users, applying for it, can have a better understanding of the work process</param>
        /// <param name="workPlace">The work place i.e. Sofiq,Bulgaria</param>
        /// <param name="requiredExperience">The experience, required for the job</param>
        /// <param name="requiredEducation">The education, required for the job</param>
        /// <returns>the id of the newly created job.</returns>
        public int CreateJob(string name,
                             decimal salary,
                             string category,
                             string description,
                             string workPlace,
                             int requiredExperience,
                             string requiredEducation)
        {
            var loggedUser = userService.GetLoggedUser();

            var job = new Job
            {
                Name                = name,
                Salary              = salary,
                Employer            = loggedUser.FirstName + " " + loggedUser.LastName,
                EmployerPhoneNumber = loggedUser.PhoneNumber,
                Category            = category,
                Description         = description,
                WorkPlace           = workPlace,
                RequiredExperience  = requiredExperience,
                RequiredEducation   = requiredEducation
            };

            context.Jobs.Add(job);
            context.SaveChanges();

            return(job.Id);
        }
        public void GetAll_MultipleApplications_AllJobApplications()
        {
            // Arrange
            foreach (JobApplicationEntity jobApplication in _jobApplicationEntities)
            {
                _jobApplicationDbContext.JobApplications.Add(jobApplication);
            }

            _jobApplicationDbContext.SaveChanges();

            // Act
            IQueryable <JobApplicationEntity> result = _jobApplicationRepository.GetAll();

            // Assert
            Assert.Equal(_jobApplicationEntities, result.ToArray());
        }
        /// <summary>
        /// This method creates a cv with the given parameters in the database
        /// by first getting the logged user
        /// </summary>
        /// <param name="education">The education of the user i.e. Masters, Bachelor, etc.</param>
        /// <param name="experience">The experience of the user (in years)</param>
        /// <param name="userId">The id of the user associated with the current cv.</param>
        /// <returns>The id of the created cv.</returns>
        public int CreateCv(string education, int experience, int userId)
        {
            User loggedUser = userService.GetLoggedUser();
            var  cv         = new CV
            {
                Education  = education,
                Experience = experience,
                UserId     = loggedUser.Id
            };

            context.CVs.Add(cv);
            context.SaveChanges(); //dont ask plz

            context.CVs.FirstOrDefault(c => c.UserId == loggedUser.Id).User = loggedUser;
            context.SaveChanges();

            return(cv.Id);
        }
Example #4
0
        public static JobApplicationDbContext GetContext(Guid id)
        {
            DbContextOptions <JobApplicationDbContext> options = new DbContextOptionsBuilder <JobApplicationDbContext>()
                                                                 .UseInMemoryDatabase(id.ToString())
                                                                 .UseLoggerFactory(MyLoggerFactory)
                                                                 .EnableSensitiveDataLogging()
                                                                 .Options;
            var context = new JobApplicationDbContext(options);

            context.SaveChanges();

            return(context);
        }
        /// <summary>
        /// this method creates a project with the given parameters
        /// by first getting the logged user and checks if he has a CV.
        /// If that is true, the creation of the project is successful and the project is added into the user's CV
        /// and all the changes are saved in the database.
        /// Otherwise, the method returns -1;
        /// </summary>
        /// <param name="name">Project name</param>
        /// <param name="technology">Project technologies</param>
        /// <param name="description">Project description</param>
        /// <param name="achievedGoals">Project achieved goals</param>
        /// <param name="futureGoals">Project future goals</param>
        /// <returns>The user that is creating the project has a Cv the method returns the project Id.
        /// Otherwise, the method returns -1.
        /// </returns>
        public int CreateProject(string name, string technology, string description, string achievedGoals, string futureGoals)
        {
            User loggeduser   = userService.GetLoggedUser();
            var  loggedUserCv = context.CVs.FirstOrDefault(c => c.UserId == loggeduser.Id);

            if (loggedUserCv != null)
            {
                var project = new Project
                {
                    Name          = name,
                    Technology    = technology,
                    Description   = description,
                    AchievedGoals = achievedGoals,
                    FutureGoals   = futureGoals
                };

                context.Projects.Add(project);
                context.CVs.FirstOrDefault(c => c.UserId == loggeduser.Id).Projects.Add(project);
                context.SaveChanges();
                return(project.Id);
            }
            return(-1);
        }
        /// <summary>
        /// This method adds a user with the given parameters in the User table of the database.
        /// First it checks if the there has already been a user created with the same username/email or phone number.
        /// If that is true, the method returns -1.
        /// Otherwise, the user gets successfuly created and added into the database
        /// </summary>
        /// <param name="firstName">The first name of the user</param>
        /// <param name="lastName">The last name of the user</param>
        /// <param name="age">The age of the user</param>
        /// <param name="email">The user's email for additional contact</param>
        /// <param name="phoneNumber">The user's phone number for additional contact</param>
        /// <param name="username">the user's username</param>
        /// <param name="password">the user's password</param>
        /// <param name="confirmPassword">a confirmation of the password (the two passwords should match)</param>
        /// <param name="isEmployer">if true, the user is an employer and can create jobs</param>
        /// <returns>The Id of the registered user or, as mentioned above, -1 if the the registration failed</returns>
        public int Register(string firstName,
                            string lastName,
                            int age,
                            string email,
                            string phoneNumber,
                            string username,
                            string password,
                            string confirmPassword,
                            bool isEmployer)
        {
            bool takenInfo = context.Users.FirstOrDefault(x => x.Username == username) != null ||
                             context.Users.FirstOrDefault(x => x.Email == email) != null ||
                             context.Users.FirstOrDefault(x => x.PhoneNumber == phoneNumber) != null;

            if (takenInfo)
            {
                return(-1);
            }
            var user = new User()
            {
                FirstName       = firstName,
                LastName        = lastName,
                Age             = age,
                Email           = email,
                PhoneNumber     = phoneNumber,
                Username        = username,
                Password        = password,
                ConfirmPassword = confirmPassword,
                IsEmployer      = isEmployer
            };

            context.Users.Add(user);
            context.SaveChanges();

            return(user.Id);
        }