Exemplo n.º 1
0
        public async Task <IActionResult> UploadCv(int applicationId, IFormFile file)
        {
            // file upload //
            if (file == null)
            {
                return(BadRequest("No file selected"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("You selected empty file."));
            }
            if (file.Length > _applicationSettings.MaxBytes)
            {
                return(BadRequest("Maximum limit for file size exceeded"));
            }
            if (!_applicationSettings.AcceptedTypes.Any(t => t == Path.GetExtension(file.FileName)))
            {
                List <string> accepted = new List <string>();
                foreach (var value in _applicationSettings.AcceptedTypes)
                {
                    accepted.Add(value);
                }
                return(BadRequest("This file type is not acceptable."));
            }


            var application = await _repo.GetApplication(applicationId);

            if (application == null)
            {
                return(BadRequest("Unknown application submition..."));
            }

            var uploadFolderPath = Path.Combine(_host.WebRootPath, "uploads"); // Path require system.io

            // create directory if doesn't exists
            // we don't want to create this folder manually in deploying
            if (!Directory.Exists(uploadFolderPath))
            {
                Directory.CreateDirectory(uploadFolderPath);
            }

            // unique file name with same extension as valid uploaded file
            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);

            application.CvName = fileName;
            await _sharedRepo.SaveAll();

            // set path for this file
            var filePath = Path.Combine(uploadFolderPath, fileName);

            // now use stream to read the file and store inside folder
            using (var stream = new FileStream(filePath /*path if file*/, FileMode.Create /*mode of file*/))
            {
                await file.CopyToAsync(stream); // now file read and stored inside folder.
            }

            return(Ok("You have successfully applied for the job! We will contact you soon after initial screening."));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostVacancy([FromBody] PostVacancyDto vacancyDto)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(BadRequest("Please signed in to your account."));
            }

            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Something went wrong..."));
            }

            if (await _repo.IsVacancy(vacancyDto.Title.ToLower()))
            {
                return(BadRequest("Job Post available for similar title."));
            }

            var validateModel = _repo.ValidateVacancy(vacancyDto);

            if (validateModel == null)
            {
                return(BadRequest("Something went wrong..."));
            }

            var currentlyLoginUserName = User.Identity.Name;
            var loggedInUser           = await _user.FindByEmailAsync(currentlyLoginUserName);

            var vacancy = _mapper.Map <Vacancy>(validateModel);

            vacancy.AppUser = loggedInUser;

            _sharedRepo.Add(vacancy);

            if (await _sharedRepo.SaveAll())
            {
                var detailedVacancy = _mapper.Map <DetailedVacancyDto>(vacancy);
                return(Created("api/vacancy/" + vacancy.Id, detailedVacancy));
            }
            return(BadRequest("Something went wrong..."));
        }
Exemplo n.º 3
0
        public async Task <User> Register(User user, string password)
        {
            user.UserName = user.UserName.ToLower();
            CreatePasswordWithEncryption(password, out byte[] passwordHash, out byte[] key);
            user.HashPassword       = passwordHash;
            user.PasswordSalt       = key;
            user.NormalizedUserName = user.UserName.ToUpper().Normalize();
            user.NormalizedEmail    = user.Email.ToUpper().Normalize();
            user.PasswordHash       = password;
            _sharedRepo.Add <User>(user);

            if (await _sharedRepo.SaveAll())
            {
                return(user);
            }

            return(null);
        }
Exemplo n.º 4
0
        public async Task <Employee> Register(Employee employee, string password)
        {
            employee.UserName = employee.UserName.ToLower();
            CreatePasswordWithEncryption(password, out byte[] passwordHash, out byte[] key);
            employee.HashPassword       = passwordHash;
            employee.Key                = key;
            employee.NormalizedUserName = employee.UserName.ToUpper().Normalize();
            employee.NormalizedEmail    = employee.Email.ToUpper().Normalize();
            employee.PasswordHash       = password;
            _sharedRepo.Add <Employee>(employee);

            if (await _sharedRepo.SaveAll())
            {
                _logger.LogInformation("employee registered successfully!");
                return(employee);
            }
            else
            {
                return(null);
            }
        }