Example #1
0
        public async Task <ExecutionResponse <MetricModel> > CreateMetric(UpdateMetricModel model)
        {
            var oldMetric = _metricQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower() && x.CompanyId == CurrentCompanyId);

            if (oldMetric != null)
            {
                throw new Exception("Metric already exists");
            }

            //save metric info
            var metric = new Metric
            {
                Name         = model.Name,
                DepartmentId = model.DepartmentId,
                Description  = model.Description,
                CompanyId    = CurrentCompanyId,
                CreateById   = _httpContext.GetCurrentSSOUserId()
            };

            await _metricCommandRepo.InsertAsync(metric);

            await _metricCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <MetricModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <MetricModel>(metric)
            });
        }
Example #2
0
        public UserService(ISSOService ssoService,
                           IRepositoryCommand <User, long> userCommandRepo,
                           IRepositoryQuery <User, long> userQueryRepo,
                           IRepositoryCommand <UserRole, long> userRoleCommandRepo,
                           IRepositoryQuery <UserRole, long> userRoleQueryRepo,
                           IRepositoryQuery <Role, long> roleQueryRepo,
                           IRepositoryQuery <Company, long> companyQueryRepo,
                           IEmailService emailService,
                           IMapper mapper,
                           IOptions <SSoSetting> sSoSetting, IHttpContextExtensionService httpContext)
        {
            _ssoSettings         = sSoSetting.Value;
            _ssoService          = ssoService;
            _userCommandRepo     = userCommandRepo;
            _userQueryRepo       = userQueryRepo;
            _userRoleCommandRepo = userRoleCommandRepo;
            _roleQueryRepo       = roleQueryRepo;
            _companyQueryRepo    = companyQueryRepo;
            _emailService        = emailService;
            _mapper            = mapper;
            _userRoleQueryRepo = userRoleQueryRepo;
            _httpContext       = httpContext;

            CurrentUserId = _httpContext.GetCurrentSSOUserId();
        }
Example #3
0
        public async Task <ExecutionResponse <VenueModel> > CreateVenue(VenueModel model)
        {
            var oldVenue = _venueQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower());

            if (oldVenue != null)
            {
                throw new Exception("Venue already exists");
            }

            //save venue info
            var venue = new Venue
            {
                Name        = model.Name,
                CompanyId   = CurrentCompanyId,
                Description = model.Description,
                CreateById  = _httpContext.GetCurrentSSOUserId()
            };

            await _venueCommandRepo.InsertAsync(venue);

            await _venueCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <VenueModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <VenueModel>(venue)
            });
        }
        public async Task <ExecutionResponse <InterviewSessionModel> > CreateInterviewSession(InterviewSessionModel model)
        {
            //save interviewSession info
            var interviewSession = new InterviewSession
            {
                StartTime   = model.StartTime,
                EndTime     = model.EndTime,
                Subject     = model.Subject,
                VenueId     = model.VenueId,
                RecruiterId = _httpContext.GetCurrentUserId(),
                CompanyId   = CurrentCompanyId,
                JobRoleId   = model.JobRoleId,
                CreateById  = _httpContext.GetCurrentSSOUserId()
            };

            await _interviewSessionCommandRepo.InsertAsync(interviewSession);

            await _interviewSessionCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <InterviewSessionModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <InterviewSessionModel>(interviewSession)
            });
        }
Example #5
0
        public async Task <ExecutionResponse <CompanyModel> > CreateCompany(CompanyModel model)
        {
            var oldCompany = _companyQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower());

            if (oldCompany != null)
            {
                throw new Exception("Company already exists");
            }

            //save company info
            var company = new Company
            {
                Name       = model.Name,
                Code       = model.Code,
                CreateById = _httpContext.GetCurrentSSOUserId()
            };

            await _companyCommandRepo.InsertAsync(company);

            await _companyCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <CompanyModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <CompanyModel>(company)
            });
        }
Example #6
0
        public async Task <ExecutionResponse <DepartmentModel> > CreateDepartment(DepartmentModel model)
        {
            var oldDepartment = _departmentQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower());

            if (oldDepartment != null)
            {
                throw new Exception("Department already exists");
            }

            //save department info
            var department = new Department
            {
                Name        = model.Name,
                CompanyId   = CurrentCompanyId,
                Description = model.Description,
                CreateById  = _httpContext.GetCurrentSSOUserId()
            };

            await _departmentCommandRepo.InsertAsync(department);

            await _departmentCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <DepartmentModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <DepartmentModel>(department)
            });
        }
Example #7
0
        public async Task Invoke(HttpContext context, IServiceProvider serviceProvider)
        {
            try
            {
                if (context.Request.Headers.ContainsKey("Authorization") && context.User.Identity.IsAuthenticated)
                {
                    // get sub
                    IHttpContextExtensionService httpExtSrv = (IHttpContextExtensionService)serviceProvider.GetService(typeof(IHttpContextExtensionService));
                    string userId = httpExtSrv.GetCurrentSSOUserId();
                    if (string.IsNullOrEmpty(userId))
                    {
                        throw new SecurityTokenValidationException();
                    }

                    IAuthService authMgr = (IAuthService)serviceProvider.GetService(typeof(IAuthService));
                    Claim[]      claims  = await authMgr.ValidateUser(userId);

                    if (claims.Length > 0)
                    {
                        context.User.AddIdentity(new ClaimsIdentity(claims));
                    }
                }
                await next(context);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                var content = GlobalExceptionFilter.GetStatusCode <object>(ex);
                var res     = JsonConvert.SerializeObject(content.responseModel, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                HttpResponse response = context.Response;
                context.Response.ContentType = "application/json";
                response.StatusCode          = (int)content.statusCode;
                await context.Response.WriteAsync(res);
            }
        }
Example #8
0
        public async Task <ExecutionResponse <JobRoleModel> > CreateJobRole(UpdateJobRoleModel model)
        {
            var oldJobRole = _jobRoleQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower() && x.Department.CompanyId == CurrentCompanyId);

            if (oldJobRole != null)
            {
                throw new Exception("Job Role already exists");
            }

            if (!_departmentQueryRepo.GetAll().Any(d => d.Id == model.DepartmentId && d.CompanyId == CurrentCompanyId))
            {
                return new ExecutionResponse <JobRoleModel>
                       {
                           ResponseCode = ResponseCode.NotFound,
                           Message      = "Department does not exist"
                       }
            }
            ;

            //save jobRole info
            var jobRole = new JobRole
            {
                Name         = model.Name,
                DepartmentId = model.DepartmentId,
                Description  = model.Description,
                CreateById   = _httpContext.GetCurrentSSOUserId()
            };

            await _jobRoleCommandRepo.InsertAsync(jobRole);

            await _jobRoleCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <JobRoleModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <JobRoleModel>(jobRole)
            });
        }
Example #9
0
        public async Task <bool> ChangePassword(string currentPassword, string newPassword)
        {
            var result = await _ssoService.ChangePassword(new SSOChangePasswordRequestModel { UserId = _httpContextService.GetCurrentSSOUserId(), CurrentPassword = currentPassword, NewPassword = newPassword });

            if (result.ResponseCode != ResponseCode.Ok)
            {
                throw new BadRequestException("Change password request failed");
            }

            return(true);
        }