Exemple #1
0
        public ActionResult Close(int pIdJob)
        {
            string deToken = this.GetToken();

            // Validate User by Token
            Company company = this.GetCompany(deToken);

            if (company != null)
            {
                Job job = ((IBaseRepository <Job>)RepositorySingleton.instance.JobRepository).Get(pIdJob);

                if (job == null || job.IdCompany != company.IdUser)
                {
                    return(BadRequest());
                }

                RepositorySingleton.instance.JobRepository.Close(job);

                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
                return(Ok(this.APIResponse));
            }
            else
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(this.APIResponse));
            }
        }
Exemple #2
0
        public ActionResult GetProfile()
        {
            string deToken = this.GetToken();

            // Validate User By Token
            Customer customer = this.GetCustomer(deToken);
            Company  company  = this.GetCompany(deToken);

            if (customer == null && company == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(APIResponse));
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);

            if (customer != null)
            {
                customer.DePassword   = string.Empty;
                this.APIResponse.Data = customer;
            }
            else // company
            {
                company.DePassword    = string.Empty;
                this.APIResponse.Data = company;
            }

            return(Ok(this.APIResponse));
        }
Exemple #3
0
        public ActionResult <List <Job> > GetByRole(int pIdRole)
        {
            string deToken = this.GetToken();

            // Validate User By Token
            Customer customer = this.GetCustomer(deToken);

            if (customer != null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
                List <Job> jobs = RepositorySingleton.instance.JobRepository.GetJobsByRole(pIdRole).Where(j => j.IsActive == true).OrderByDescending(j => j.DtRegister).ToList();

                foreach (Job job in jobs)
                {
                    job.Company.DePassword = null;
                }

                this.APIResponse.Data = jobs;

                return(Ok(this.APIResponse));
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
            return(Unauthorized(this.APIResponse));
        }
Exemple #4
0
        public ActionResult Register(RegisterUpdateUserRequest pRegisterUpdateUserRequest)
        {
            if (pRegisterUpdateUserRequest == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                return(BadRequest(this.APIResponse));
            }

            // Validations
            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);

            this.ValidateUserType(pRegisterUpdateUserRequest);
            this.ValidateNmUser(pRegisterUpdateUserRequest);
            this.ValidateDeEmail(pRegisterUpdateUserRequest);
            this.ValidateIdRole(pRegisterUpdateUserRequest);
            this.ValidateDePassword(pRegisterUpdateUserRequest);

            if (this.APIResponse.Errors.Count > 0)
            {
                return(BadRequest(this.APIResponse));
            }

            // create new user
            if (pRegisterUpdateUserRequest.UserType == (int)UserType.Customer)
            {
                ((IBaseRepository <Customer>)RepositorySingleton.instance.CustomerRepository).Add(new Customer
                {
                    NmUser      = pRegisterUpdateUserRequest.NmUser,
                    DeEmail     = pRegisterUpdateUserRequest.DeEmail,
                    DePassword  = pRegisterUpdateUserRequest.DePassword,
                    IdRole      = pRegisterUpdateUserRequest.IdRole,
                    NuTelephone = pRegisterUpdateUserRequest.NuTelephone,
                    DtRegister  = DateTime.Now
                });
            }
            else if (pRegisterUpdateUserRequest.UserType == (int)UserType.Company)
            {
                ((IBaseRepository <Company>)RepositorySingleton.instance.CompanyRepository).Add(new Company
                {
                    NmUser      = pRegisterUpdateUserRequest.NmUser,
                    DeEmail     = pRegisterUpdateUserRequest.DeEmail,
                    DePassword  = pRegisterUpdateUserRequest.DePassword,
                    NuTelephone = pRegisterUpdateUserRequest.NuTelephone,
                    DtRegister  = DateTime.Now
                });
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }
Exemple #5
0
        public ActionResult UpdatePassword(RegisterUpdateUserRequest pRegisterUpdateUserRequest)
        {
            string deToken = this.GetToken();

            // Validate User By Token
            Customer customer = this.GetCustomer(deToken);
            Company  company  = this.GetCompany(deToken);

            if (customer == null && company == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(APIResponse));
            }

            // Validate Body Request
            if (pRegisterUpdateUserRequest == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                return(BadRequest(this.APIResponse));
            }

            // Validations
            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);

            this.ValidateDePassword(pRegisterUpdateUserRequest);

            if (this.APIResponse.Errors.Count > 0)
            {
                return(BadRequest(this.APIResponse));
            }

            // update user
            if (customer != null)
            {
                customer.DePassword = pRegisterUpdateUserRequest.DePassword;

                ((IBaseRepository <Customer>)RepositorySingleton.instance.CustomerRepository).Update(customer);
            }
            else // company
            {
                company.DePassword = pRegisterUpdateUserRequest.DePassword;

                ((IBaseRepository <Company>)RepositorySingleton.instance.CompanyRepository).Update(company);
            }


            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }
        public ActionResult Accept(AcceptRejectCandidateRequest pAcceptRejectCandidateRequest)
        {
            string deToken = this.GetToken();

            // Validate User by Token
            Company   company   = this.GetCompany(deToken);
            Candidate candidate = ((IBaseRepository <Candidate>)RepositorySingleton.instance.CandidateRepository).Get(pAcceptRejectCandidateRequest.IdCandidate);
            Job       job       = ((IBaseRepository <Job>)RepositorySingleton.instance.JobRepository).Get(pAcceptRejectCandidateRequest.IdJob);

            if (company == null || candidate == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(this.APIResponse));
            }
            else
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);

                if (candidate.IdJob != job.IdJob)
                {
                    this.APIResponse.AddError("", string.Format(ValidationMessageConstant.CandidateIsNotFromThisJob, job.DeTitle));
                }
                else if (job.IdCompany != company.IdUser)
                {
                    this.APIResponse.AddError("", string.Format(ValidationMessageConstant.JobIsNotFromThisCompany, company.NmUser));
                }
                else if (job.IsActive == false)
                {
                    this.APIResponse.AddError("", ValidationMessageConstant.JobIsNotActive);
                }

                // Return Bad Request
                if (this.APIResponse.Errors.Count > 0)
                {
                    return(BadRequest(this.APIResponse));
                }
            }


            candidate.WasAccept = true;
            job.IsActive        = false;

            ((IBaseRepository <Candidate>)RepositorySingleton.instance.CandidateRepository).Update(candidate);
            ((IBaseRepository <Job>)RepositorySingleton.instance.JobRepository).Update(job);

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }
Exemple #7
0
        public ActionResult GetByCompany()
        {
            string deToken = this.GetToken();

            // Validate User by Token
            Company company = this.GetCompany(deToken);

            if (company != null)
            {
                this.APIResponse      = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
                this.APIResponse.Data = RepositorySingleton.instance.JobRepository.GetJobsByCompany(company.IdUser).OrderByDescending(j => j.DtRegister).ToList();
                return(Ok(this.APIResponse));
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
            return(Unauthorized(this.APIResponse));
        }
        public ActionResult TryLogin(LoginRequest pLoginRequest)
        {
            var         user = RepositorySingleton.instance.UserBaseRepository.Get(pLoginRequest.DeEmail, pLoginRequest.DePassword, (UserType)pLoginRequest.UserType);
            APIResponse apiResponse;

            if (user == null)
            {
                apiResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                apiResponse.AddError("validation", ValidationMessageConstant.LoginEmailOrPasswordWrong);

                return(BadRequest(apiResponse));
            }
            else
            {
                string deToken = this.GenerateToken();

                user.DeToken = deToken;
                UserToken userToken = new UserToken
                {
                    DeToken  = deToken,
                    DtExpire = DateTime.Now.AddHours(AppSettingsSingleton.instance.JWT_ExpiresHours),
                    IsActive = true
                };

                if ((UserType)pLoginRequest.UserType == UserType.Company)
                {
                    userToken.IdCompany = user.IdUser;
                }
                else if ((UserType)pLoginRequest.UserType == UserType.Customer)
                {
                    userToken.IdCustomer = user.IdUser;
                }

                ((IBaseRepository <UserToken>)RepositorySingleton.instance.UserTokenRepository).Add(userToken);

                // for security
                user.DePassword = null;
                user.UserType   = (UserType)pLoginRequest.UserType;
            }

            this.APIResponse      = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            this.APIResponse.Data = user;

            return(Ok(this.APIResponse));
        }
        public ActionResult Get(int pIdJob)
        {
            string deToken = this.GetToken();

            // Validate User by Token
            Company company = this.GetCompany(deToken);

            if (company == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(this.APIResponse));
            }

            this.APIResponse      = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            this.APIResponse.Data = RepositorySingleton.instance.CandidateRepository.GetAll(pIdJob);

            // security password
            foreach (Candidate candidate in (List <Candidate>) this.APIResponse.Data)
            {
                candidate.Customer.DePassword = string.Empty;
            }

            return(Ok(APIResponse));
        }
        public ActionResult Post(int pIdJob)
        {
            string deToken = this.GetToken();

            // Validate User By Token
            Customer customer = this.GetCustomer(deToken);

            if (customer == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(this.APIResponse));
            }

            // Validate if already is a candidate
            if (RepositorySingleton.instance.CandidateRepository.Get(customer.IdUser, pIdJob) != null)
            {
                this.APIResponse = Factories.APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                this.APIResponse.AddError("AlreadyRegister", ValidationMessageConstant.CadidateAlreadyRegisteredForTheJob);
                return(BadRequest(this.APIResponse));
            }

            // Create candidate
            Candidate candidate = new Candidate
            {
                DtRegister = DateTime.Now,
                IdCustomer = customer.IdUser,
                IdJob      = pIdJob,
                WasAccept  = false,
                WasReject  = false
            };

            ((IBaseRepository <Candidate>)RepositorySingleton.instance.CandidateRepository).Add(candidate);

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }
Exemple #11
0
 public async Task <ActionResult> Get()
 {
     this.APIResponse      = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
     this.APIResponse.Data = await((IBaseRepository <Role>)RepositorySingleton.instance.RoleRepository).GetAllAsync();
     return(Ok(this.APIResponse));
 }
 public ActionResult Get(int pIdCompany)
 {
     this.APIResponse      = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
     this.APIResponse.Data = ((IBaseRepository <Company>)RepositorySingleton.instance.RoleRepository).Get(pIdCompany);
     return(Ok(this.APIResponse));
 }
Exemple #13
0
        public ActionResult CreateJob(JobAddRequest pJobAddRequest)
        {
            try
            {
                string deToken = this.GetToken();

                // Validate User by Token
                Company company = this.GetCompany(deToken);

                if (company == null)
                {
                    this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                    return(Unauthorized(this.APIResponse));
                }

                // Validate Request
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                if (string.IsNullOrEmpty(pJobAddRequest.DeTitle))
                {
                    this.APIResponse.AddError("DeTitle", ValidationMessageConstant.RequiredField);
                }
                if (string.IsNullOrEmpty(pJobAddRequest.DeDescription))
                {
                    this.APIResponse.AddError("DeDescription", ValidationMessageConstant.RequiredField);
                }
                if (pJobAddRequest.IdRole <= 0)
                {
                    this.APIResponse.AddError("IdRole", ValidationMessageConstant.RequiredField);
                }
                else
                {
                    Role role = ((IBaseRepository <Role>)RepositorySingleton.instance.RoleRepository).Get(pJobAddRequest.IdRole);
                    if (role == null)
                    {
                        this.APIResponse.AddError("IdRole", ValidationMessageConstant.InvalidValue);
                    }
                }

                if (this.APIResponse.Errors.Count() > 0)
                {
                    return(BadRequest(this.APIResponse));
                }

                // Create New Job
                Job job = new Job {
                    IdCompany     = company.IdUser,
                    DtRegister    = DateTime.Now,
                    IsActive      = true,
                    DeDescription = pJobAddRequest.DeDescription,
                    DeTitle       = pJobAddRequest.DeTitle,
                    IdRole        = pJobAddRequest.IdRole,
                    VlSalaryMin   = pJobAddRequest.VlSalaryMin,
                    VlSalaryMax   = pJobAddRequest.VlSalaryMax
                };

                // Insert in DB
                ((IBaseRepository <Job>)RepositorySingleton.instance.JobRepository).Add(job);
            }
            catch (Exception ex)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                this.APIResponse.AddError("Exception", $"Message: {ex.Message.ToStringOrEmpty()}");
                this.APIResponse.AddError("Exception", $"Stack Trace: {ex.StackTrace.ToStringOrEmpty()}");
                this.APIResponse.AddError("Exception", $"Inner Exception: {ex.InnerException.ToStringOrEmpty()}");

                return(BadRequest(this.APIResponse));
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }
Exemple #14
0
        public ActionResult UpdateProfile(RegisterUpdateUserRequest pRegisterUpdateUserRequest)
        {
            string deToken = this.GetToken();

            // Validate User By Token
            Customer customer = this.GetCustomer(deToken);
            Company  company  = this.GetCompany(deToken);

            if (customer == null && company == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.Unauthorized);
                return(Unauthorized(APIResponse));
            }

            // Validate Body Request
            if (pRegisterUpdateUserRequest == null)
            {
                this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);
                return(BadRequest(this.APIResponse));
            }

            // Validations
            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.BadRequest);

            // set userType for validations
            pRegisterUpdateUserRequest.UserType = (customer == null) ? (int)UserType.Company : (int)UserType.Customer;

            this.ValidateNmUser(pRegisterUpdateUserRequest);
            this.ValidateDeEmail(pRegisterUpdateUserRequest, (customer == null) ? (UserBase)company : (UserBase)customer);
            this.ValidateIdRole(pRegisterUpdateUserRequest);
            //this.ValidateDePassword(pRegisterUpdateUserRequest);

            if (this.APIResponse.Errors.Count > 0)
            {
                return(BadRequest(this.APIResponse));
            }

            // update user
            if (customer != null)
            {
                customer.NmUser  = pRegisterUpdateUserRequest.NmUser;
                customer.DeEmail = pRegisterUpdateUserRequest.DeEmail;
                //customer.DePassword = pRegisterUpdateUserRequest.DePassword;
                customer.IdRole      = pRegisterUpdateUserRequest.IdRole;
                customer.NuTelephone = pRegisterUpdateUserRequest.NuTelephone;

                ((IBaseRepository <Customer>)RepositorySingleton.instance.CustomerRepository).Update(customer);
            }
            else // company
            {
                company.NmUser  = pRegisterUpdateUserRequest.NmUser;
                company.DeEmail = pRegisterUpdateUserRequest.DeEmail;
                //company.DePassword = pRegisterUpdateUserRequest.DePassword;
                company.NuTelephone = pRegisterUpdateUserRequest.NuTelephone;

                ((IBaseRepository <Company>)RepositorySingleton.instance.CompanyRepository).Update(company);
            }

            this.APIResponse = APIResponseFactory.Create(System.Net.HttpStatusCode.OK);
            return(Ok(this.APIResponse));
        }