Ejemplo n.º 1
0
        public Task <BaseResponse <List <AcademicQualificatonDTO> > > Handle(PostAcademicQualificationsCommand request, CancellationToken cancellationToken)
        {
            var academicDTO = new List <AcademicQualificatonDTO>();

            if (request.Qualifications.Any())
            {
                foreach (var qualification in request.Qualifications)
                {
                    var newQualification = new UserAcademicQualification
                    {
                        Academy       = qualification.Academy,
                        Certification = qualification.Certification,
                        EndYear       = qualification.EndYear,
                        StartYear     = qualification.StartYear,
                        TimeCreated   = DateTime.Now,
                        TimeUpdated   = DateTime.Now,
                        UserId        = request.UserId
                    };
                    _context.UserAcademicQualifications.Add(newQualification);

                    academicDTO.Add(new AcademicQualificatonDTO
                    {
                        Academy       = newQualification.Academy,
                        Certification = newQualification.Certification,
                        EndYear       = newQualification.EndYear,
                        StartYear     = newQualification.StartYear,
                    });
                }
                _context.SaveChanges();

                return(Task.FromResult(new BaseResponse <List <AcademicQualificatonDTO> >(true, $"Academic qualifications posted successfully", academicDTO)));
            }

            return(Task.FromResult(new BaseResponse <List <AcademicQualificatonDTO> >(false, $"No academic qualification provided")));
        }
Ejemplo n.º 2
0
        public async Task <BaseResponse <ProfileDTO> > Handle(PostProfileCommand request, CancellationToken cancellationToken)
        {
            var user = await _userManager.FindByIdAsync($"{request.UserId}");

            if (user == null)
            {
                return(new BaseResponse <ProfileDTO>(false, "User does not exist"));
            }

            var profile = _context.UserProfiles.FirstOrDefault(p => p.UserId == request.UserId);

            if (profile == null)
            {
                //new profile
                var newProfile = new UserProfile
                {
                    Address       = request.Address,
                    DateOfBirth   = request.DateOfBirth,
                    Gender        = request.Gender,
                    LGAOfOrigin   = request.LGAOfOrigin,
                    Nationality   = request.Nationality,
                    StateOfOrigin = request.StateOfOrigin,
                    TimeCreated   = DateTime.Now,
                    TimeUpdated   = DateTime.Now,
                    TownOfOrigin  = request.TownOfOrigin,
                    UserId        = user.Id
                };
                _context.UserProfiles.Add(newProfile);
                _context.SaveChanges();

                return(new BaseResponse <ProfileDTO>(true, "Profile updated successfully", newProfile.ToDTO(user)));
            }

            profile.Address       = request.Address;
            profile.DateOfBirth   = request.DateOfBirth;
            profile.Gender        = request.Gender;
            profile.LGAOfOrigin   = request.LGAOfOrigin;
            profile.Nationality   = request.Nationality;
            profile.StateOfOrigin = request.StateOfOrigin;
            profile.TimeUpdated   = DateTime.Now;
            profile.TownOfOrigin  = request.TownOfOrigin;
            profile.UserId        = user.Id;

            _context.SaveChanges();

            return(new BaseResponse <ProfileDTO>(true, "Profile updated successfully", profile.ToDTO(user)));
        }
Ejemplo n.º 3
0
        public async Task <BaseResponse> Handle(RegisterCommand request, CancellationToken cancellationToken)
        {
            var email        = request.EmailAddress.Trim().ToLowerInvariant();
            var existingUser = _userManager.FindByEmailAsync(email).Result;

            if (existingUser != null)
            {
                return(new BaseResponse(false, "User with email already exists"));
            }

            var newUser = new BB360User
            {
                Email          = email,
                UserName       = email,
                EmailConfirmed = false,
                PhoneNumber    = request.PhoneNumber,
                FirstName      = request.FirstName,
                LastName       = request.LastName,
                TimeCreated    = DateTime.Now,
                TimeUpdated    = DateTime.Now,
                UserType       = (int)UserTypeEnum.Candidate
            };

            // string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            // string password = new string(Enumerable.Repeat(chars, 10).Select(s => s[new Random().Next(s.Length)]).ToArray());

            var registerAttempt = _userManager.CreateAsync(newUser, request.Password).Result;

            if (!registerAttempt.Succeeded)
            {
                var errors = registerAttempt.Errors.Select(x => x.Description).ToList();
                return(new BaseResponse(false, "There were errors found in your submission. Please review and retry"));
            }

            var application = new JobApplication
            {
                Comment              = request.Comment,
                JobRole              = request.JobRole,
                LinkedInProfileLink  = request.LinkedInProfileLink,
                NewsSource           = request.NewsSource,
                PortfolioLink        = request.PortfolioLink,
                PrimarySkills        = JsonConvert.SerializeObject(request.PrimarySkills),
                ProblemSolverOpinion = request.ProblemSolverOpinion,
                ReferralName         = request.ReferralName,
                RiskOutcome          = request.RiskOutcome,
                RiskSituation        = request.RiskSituation,
                TimeCreated          = DateTime.Now,
                TimeUpdated          = DateTime.Now,
                UserId       = newUser.Id,
                IsSuccessful = false
            };

            _context.Add(application);
            _context.SaveChanges();

            // _ =_mediator.Send(new SendEmailConfirmationCommand { User = newUser });

            return(await Task.FromResult(new BaseResponse(true, "Job application submitted successfully. A new account has been created for you. Login credentials has been sent to your email address")));
        }
Ejemplo n.º 4
0
        public async Task <BaseResponse <string> > Handle(UploadDocumentCommand request, CancellationToken cancellationToken)
        {
            if (request.DocumentFile.Length < 1 || request.DocumentFile == null)
            {
                return(new BaseResponse <string>(false, $"File not attached. Attach file and try again"));
            }

            //Validate file extension
            var ext = Path.GetExtension(request.DocumentFile.FileName);

            string[] formats = new string[] { ".jpg", ".jpeg", ".png", ".pdf", ".doc", ".docx" };
            if (!formats.Contains(ext))
            {
                return(new BaseResponse <string>(false, "Invalid file extension, kindly ensure file is in jpg, jpeg, png, doc, docx or pdf format"));
            }

            var template      = _context.DocumentTemplates.Find(request.TemplateId);
            var dbPath        = Path.Combine("Documents", $"{request.UserId}", $"{template.Name.Replace("\\", "-").Replace("/", "-")}");
            var directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", dbPath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            var docName    = DateTime.Now.ToString("yyyyMMddHHmmss");
            var path       = Path.Combine(directoryPath, $"{docName}{ext}");
            var dbPathFull = Path.Combine(dbPath, $"{docName}{ext}");

            try
            {
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await request.DocumentFile.CopyToAsync(stream);
                }

                var document = new UserDocument
                {
                    DocumentTemplateId = request.TemplateId,
                    FilePath           = dbPathFull,
                    Name        = template.Name,
                    TimeCreated = DateTime.Now,
                    TimeUpdated = DateTime.Now,
                    UserId      = request.UserId
                };
                _context.UserDocuments.Add(document);
                _context.SaveChanges();

                return(new BaseResponse <string>(true, "Document upload is successful"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Application ran into an error while trying to upload document");
                return(new BaseResponse <string>(false, "Document upload failed. Try again."));
            }
        }
Ejemplo n.º 5
0
        public Task <BaseResponse <List <ProfessionalExperienceDTO> > > Handle(PostProfessionalExperienceCommand request, CancellationToken cancellationToken)
        {
            var professionalDTO = new List <ProfessionalExperienceDTO>();

            if (request.Experience.Any())
            {
                foreach (var experience in request.Experience)
                {
                    var newExperience = new UserProfessionalExperience
                    {
                        EndYear      = experience.EndYear,
                        StartYear    = experience.StartYear,
                        TimeCreated  = DateTime.Now,
                        TimeUpdated  = DateTime.Now,
                        UserId       = request.UserId,
                        Description  = experience.Description,
                        JobRole      = experience.JobRole,
                        Organization = experience.Organization
                    };
                    _context.UserProfessionalExperiences.Add(newExperience);

                    professionalDTO.Add(new ProfessionalExperienceDTO
                    {
                        EndYear      = experience.EndYear,
                        StartYear    = experience.StartYear,
                        Description  = experience.Description,
                        JobRole      = experience.JobRole,
                        Organization = experience.Organization
                    });
                }
                _context.SaveChanges();

                return(Task.FromResult(new BaseResponse <List <ProfessionalExperienceDTO> >(true, $"Professional experience posted successfully", professionalDTO)));
            }

            return(Task.FromResult(new BaseResponse <List <ProfessionalExperienceDTO> >(false, $"No professional experience provided")));
        }