public SkillViewModel()
 {
     if (this._skillRequestModel == null)
     {
         this._skillRequestModel = new SkillRequestModel();
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateSkill(int id, [FromBody] SkillRequestModel skillRequestModel)
        {
            var app = await _skillService.UpdateSkill(id, skillRequestModel);

            if (app.AppResult.Result == false)
            {
                return(BadRequest(app.AppResult));
            }
            return(Ok(app.AppResult));
        }
Esempio n. 3
0
        public async Task <IActionResult> InsertSkill([FromBody] SkillRequestModel skillRequestModel)
        {
            var app = await _skillService.InserSkill(skillRequestModel);

            if (app.AppResult.Result == false)
            {
                return(BadRequest(app.AppResult));
            }
            return(Ok(app.AppResult));
        }
Esempio n. 4
0
        /// <summary>
        /// Get PersonCategory
        /// </summary>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <PersonCategory> GetPersonCategory(SkillRequestModel skillRequestModel)
        {
            int numberItemPersonCategory = await _skillRepository.GetNumberItemPersonCategory();

            int orderIndex = 1;

            if (numberItemPersonCategory > 0)
            {
                orderIndex = await _skillRepository.GetMaxOrderIndex() + 1;
            }
            PersonCategory personCategory = new PersonCategory
            {
                PersonId   = skillRequestModel.PersonId,
                CategoryId = skillRequestModel.CategoryId,
                OrderIndex = orderIndex,
                CreatedBy  = WebAPI.Helpers.HttpContext.CurrentUser,
                UpdatedBy  = WebAPI.Helpers.HttpContext.CurrentUser
            };

            return(personCategory);
        }
Esempio n. 5
0
        /// <summary>
        /// Get List PersonTechnology
        /// </summary>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <List <PersonTechnology> > GetListPersonTechnology(SkillRequestModel skillRequestModel)
        {
            List <PersonTechnology> personTechnologies = new List <PersonTechnology>();

            foreach (var item in skillRequestModel.TechnologyId)
            {
                Technology modelTechnology = await _technologyRepository.FindAsync(item);

                if (modelTechnology != null)
                {
                    PersonTechnology personTechnology = new PersonTechnology
                    {
                        PersonId     = skillRequestModel.PersonId,
                        TechnologyId = modelTechnology.Id,
                        CreatedBy    = WebAPI.Helpers.HttpContext.CurrentUser,
                        UpdatedBy    = WebAPI.Helpers.HttpContext.CurrentUser,
                        CreatedAt    = DateTime.Now,
                        UpdatedAt    = DateTime.Now
                    };
                    personTechnologies.Add(personTechnology);
                }
            }
            return(personTechnologies);
        }
Esempio n. 6
0
        /// <summary>
        /// Update Skill
        /// </summary>
        /// <param name="id"></param>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> UpdateSkill(int id, SkillRequestModel skillRequestModel)
        {
            model.AppResult.Result  = false;
            model.SkillRequestModel = skillRequestModel;
            if (id <= 0)
            {
                model.AppResult.Message = "PersonId not exist!";
            }
            else if (skillRequestModel.TechnologyId.Count <= 0)
            {
                model.AppResult.Message = "TechnologyId not exist!";
            }
            else if (skillRequestModel.CategoryId <= 0)
            {
                model.AppResult.Message = "CategoryId not exist!";
            }
            else
            {
                PersonCategory personCategory = await _skillRepository.GetPersonCategoryAsync(id, null, null);

                if (personCategory == null)
                {
                    model.AppResult.Message = "Update failure, Skill not exists";
                }
                else
                {
                    var modelCategory = await _categoryRepository.FindAsync(skillRequestModel.CategoryId);

                    if (modelCategory == null)
                    {
                        model.AppResult.Message = "Update failure, Category not exists";
                    }
                    else
                    {
                        List <PersonTechnology> personTechnologies = new List <PersonTechnology>();
                        personTechnologies = await GetListPersonTechnology(skillRequestModel);

                        if (personTechnologies.Count > 0)
                        {
                            personCategory.CategoryId = skillRequestModel.CategoryId;
                            personCategory.CreatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            personCategory.UpdatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            await _skillRepository.DeletePersonTechnologyToUpdateAsync(personCategory);

                            await _skillRepository.InsertListPersonTechnologyAsync(personTechnologies);

                            if (id > 0 && skillRequestModel.PersonId > 0)
                            {
                                List <Category> listResult = new List <Category>();
                                modelCategory = await _skillRepository.GetSkillInsertAsync(id, skillRequestModel.PersonId);

                                if (modelCategory != null)
                                {
                                    model.AppResult.Result  = true;
                                    model.AppResult.Message = Constants.Constant.UPDATE_SUCCESS;
                                    listResult.Add(modelCategory);
                                    model.AppResult.DataResult = GetListSkillResource(listResult).FirstOrDefault();
                                }
                            }
                        }
                        else
                        {
                            model.AppResult.Message = "Update failure, Technology not exists";
                        }
                    }
                }
            }
            return(model);
        }
Esempio n. 7
0
        /// <summary>
        /// Inser Skill
        /// </summary>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> InserSkill(SkillRequestModel skillRequestModel)
        {
            model.AppResult.Result = false;
            if (skillRequestModel.PersonId <= 0)
            {
                model.AppResult.Message = "PersonId not exist!";
            }
            else if (skillRequestModel.CategoryId <= 0)
            {
                model.AppResult.Message = "CategoryId not exist!";
            }
            else if (skillRequestModel.TechnologyId.Count <= 0)
            {
                model.AppResult.Message = "TechnologyId not exist!";
            }
            else
            {
                model.SkillRequestModel = skillRequestModel;
                PersonCategory personCategory = await GetPersonCategory(skillRequestModel);

                List <PersonTechnology> personTechnologies = await GetListPersonTechnology(skillRequestModel);

                Category modelCategory    = new Category();
                int      idPersonCategory = 0;
                int      idPerson         = 0;
                modelCategory = await _categoryRepository.FindAsync(personCategory.CategoryId);

                if (modelCategory == null)
                {
                    model.AppResult.Message = "Create failure, Category not exists";
                }
                else
                {
                    if (personTechnologies.Count > 0)
                    {
                        if (await _skillRepository.CheckPersonCategoryAsync(personCategory))
                        {
                            if (await _skillRepository.CheckNumberTechnology(personCategory))
                            {
                                model.AppResult.Message = "Create failure, Skill already exists";
                                return(model);
                            }
                            else
                            {
                                personCategory.OrderIndex = await _skillRepository.GetMaxOrderIndex() + 1;

                                personCategory.UpdatedAt = DateTime.Now;
                                var resultNumberCategory = await _skillRepository.UpdatePersonCategoryToInsertAsync(personCategory);

                                if (resultNumberCategory > 0)
                                {
                                    idPerson         = personCategory.PersonId;
                                    idPersonCategory = (await _skillRepository.GetPersonCategoryAsync(null, personCategory.PersonId, personCategory.CategoryId)).Id;
                                    var resultNumberTechnology = await InsertListPersonTechnology(personTechnologies);

                                    if (resultNumberTechnology <= 0)
                                    {
                                        model.AppResult.Message = "Create failure, Technology not exists";
                                    }
                                }
                                else
                                {
                                    model.AppResult.Message = "Create failure, Category not exists";
                                }
                            }
                        }
                        else
                        {
                            PersonCategory modelPersonCategory = await _skillRepository.CheckPersonCategoryOnDeleteAsync(personCategory);

                            if (modelPersonCategory == null)
                            {
                                idPersonCategory = await _skillRepository.InsertPersonCategoryAsync(personCategory);

                                idPerson = skillRequestModel.PersonId;
                            }
                            else
                            {
                                modelPersonCategory.OrderIndex = await _skillRepository.GetMaxOrderIndex() + 1;

                                modelPersonCategory.UpdatedAt = DateTime.Now;
                                var resultNumberCategor = await _skillRepository.UpdatePersonCategoryToInsertAsync(modelPersonCategory);

                                if (resultNumberCategor > 0)
                                {
                                    idPersonCategory = modelPersonCategory.Id;
                                    idPerson         = modelPersonCategory.PersonId;
                                }
                                else
                                {
                                    model.AppResult.Message = "Create failure, Category not exists";
                                }
                            }
                            var resultNumberTechnology = await InsertListPersonTechnology(personTechnologies);

                            if (resultNumberTechnology <= 0)
                            {
                                model.AppResult.Message = "Create failure, Technology not exists";
                            }
                        }
                        if (idPersonCategory > 0 && idPerson > 0)
                        {
                            List <Category> listResult = new List <Category>();
                            modelCategory = await _skillRepository.GetSkillInsertAsync(idPersonCategory, idPerson);

                            if (modelCategory != null)
                            {
                                model.AppResult.Result  = true;
                                model.AppResult.Message = Constants.Constant.INSERT_SUCCESS;
                                listResult.Add(modelCategory);
                                model.AppResult.DataResult = GetListSkillResource(listResult).FirstOrDefault();
                            }
                        }
                    }
                    else
                    {
                        model.AppResult.Message = "Create failure, Technology not exists";
                    }
                }
            }
            return(model);
        }
Esempio n. 8
0
        public async Task <AppResult> ImportFile(FileUpload file, int?id)
        {
            AppResult appResult = new AppResult();
            var       fileName  = file.files.FileName;

            if (!ImportFileHandling.HasFileExtension(Path.GetExtension(fileName)))
            {
                appResult.Result  = false;
                appResult.Message = "CV Import Failed, Invalid file format!";
                return(appResult);
            }
            var list = await ImportFileHandling.GetInformationCV(file.files);

            if (list.Count > 0)
            {
                var resultCheckFile = ImportFileHandling.CheckFile(list);
                if (resultCheckFile.Result)
                {
                    int idPerson = 0;
                    List <SkillRequestModel> listSkill = new List <SkillRequestModel>();
                    List <int> listIdWorkHistory       = new List <int>();
                    List <SaveWorkHistoryResource> saveWorkHistoryResources = new List <SaveWorkHistoryResource>();
                    List <int> listIdEducation = new List <int>();
                    List <SaveEducationResource> saveEducationResources = new List <SaveEducationResource>();
                    List <int> listIdCertificate = new List <int>();
                    List <SaveCertificateResource> saveCertificateResources = new List <SaveCertificateResource>();
                    List <int>           listIdSkill        = new List <int>();
                    List <SkillResource> skillRequestModels = new List <SkillResource>();
                    List <int>           listIdProject      = new List <int>();
                    List <Project>       listProject        = new List <Project>();
                    try
                    {
                        using (TransactionScope txScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                        {
                            Person person = ImportFileHandling.GetPerson(list);
                            Image  image  = await ImportFileHandling.GetImageCV(file.files);

                            if (id == null)
                            {
                                var resultPerson = await _personService.InsertPersonToImportFile(person, image);

                                appResult = resultPerson.AppResult;
                                idPerson  = resultPerson.PersonInfo.Id;
                            }
                            else
                            {
                                idPerson = (int)id;
                                if (idPerson > 0)
                                {
                                    var tempPerson = await _personService.GetPersonById(idPerson);

                                    var modelPerson = (Person)tempPerson;
                                    if (modelPerson != null)
                                    {
                                        person.Id = (int)id;
                                        var resultPerson = await _personService.UpdatePersonToImportFile(person, image);

                                        appResult = resultPerson.AppResult;
                                        if (appResult.Result)
                                        {
                                            var listWorkHistoryResourceByPersonId = await _workHistoryService.GetWorkHistoryByPersonId(idPerson);

                                            saveWorkHistoryResources = listWorkHistoryResourceByPersonId.ToList();
                                            if (saveWorkHistoryResources != null)
                                            {
                                                foreach (var item in saveWorkHistoryResources)
                                                {
                                                    listIdWorkHistory.Add(item.Id);
                                                }
                                                if (listIdWorkHistory != null)
                                                {
                                                    foreach (var item in listIdWorkHistory)
                                                    {
                                                        await _workHistoryService.DeleteWorkHistory(item);
                                                    }
                                                }
                                            }
                                            var listEducationByPersonId = await _educationService.GetEducationByPersonId(idPerson);

                                            saveEducationResources = listEducationByPersonId.ToList();
                                            if (saveEducationResources != null)
                                            {
                                                foreach (var item in saveEducationResources)
                                                {
                                                    listIdEducation.Add(item.Id);
                                                }
                                                if (listIdEducation != null)
                                                {
                                                    foreach (var item in listIdEducation)
                                                    {
                                                        await _educationService.DeleteEducation(item);
                                                    }
                                                }
                                            }
                                            var listCertificateByPersonId = await _certificateService.GetCertificateByPersonId(idPerson);

                                            saveCertificateResources = listCertificateByPersonId.ToList();
                                            if (saveCertificateResources != null)
                                            {
                                                foreach (var item in saveCertificateResources)
                                                {
                                                    listIdCertificate.Add(item.Id);
                                                }
                                                if (listIdCertificate != null)
                                                {
                                                    foreach (var item in listIdCertificate)
                                                    {
                                                        await _certificateService.DeleteCertificate(item);
                                                    }
                                                }
                                            }
                                            var listSkillByPeronId = await _skillService.GetSkillByPerson(idPerson);

                                            skillRequestModels = listSkillByPeronId.ToList();
                                            if (skillRequestModels != null)
                                            {
                                                foreach (var item in skillRequestModels)
                                                {
                                                    listIdSkill.Add(item.PersonCategoryId);
                                                }
                                                if (listIdSkill != null)
                                                {
                                                    foreach (var item in listIdSkill)
                                                    {
                                                        await _skillService.DeleteSkill(item);
                                                    }
                                                }
                                            }
                                            var listProjectByPersonId = await _projectService.GetProjectByPersonId(idPerson);

                                            listProject = listProjectByPersonId.ToList();
                                            if (listProject != null)
                                            {
                                                foreach (var item in listProject)
                                                {
                                                    listIdProject.Add(item.Id);
                                                }
                                                if (listIdProject != null)
                                                {
                                                    foreach (var item in listIdProject)
                                                    {
                                                        await _projectService.DeleteProject(item);
                                                    }
                                                }
                                            }
                                        }
                                        idPerson = resultPerson.PersonInfo.Id;
                                    }
                                    else
                                    {
                                        appResult.Result  = false;
                                        appResult.Message = "CV Import Failed, CV not exist";
                                        return(appResult);
                                    }
                                }
                            }
                            if (idPerson > 0)
                            {
                                List <CreateWorkHistoryResource> workHistoryResources = ImportFileHandling.GetListWorkHistory(list, idPerson);
                                if (workHistoryResources != null)
                                {
                                    foreach (var item in workHistoryResources)
                                    {
                                        if (item != null)
                                        {
                                            await _workHistoryService.CreateWorkHistory(item);
                                        }
                                    }
                                }
                                List <CreateEducationResource> createEducationResources = ImportFileHandling.GetListEducation(list, idPerson);
                                if (createEducationResources != null)
                                {
                                    foreach (var item in createEducationResources)
                                    {
                                        if (item != null)
                                        {
                                            await _educationService.CreateEducation(item);
                                        }
                                    }
                                }
                                List <CreateCertificateResource> createCertificateResources = ImportFileHandling.GetListCertifiate(list, idPerson);
                                if (createCertificateResources != null)
                                {
                                    foreach (var item in createCertificateResources)
                                    {
                                        if (item != null)
                                        {
                                            await _certificateService.CreateCertificate(item);
                                        }
                                    }
                                }
                                List <Category> categories = ImportFileHandling.GetListCategory(list);
                                List <int>      Category   = new List <int>();
                                if (categories != null)
                                {
                                    listSkill = new List <SkillRequestModel>();
                                    foreach (var groupItem in categories)
                                    {
                                        var resultCategory = await _categoryService.InsertCategory(groupItem);

                                        int idCategory = resultCategory.Category.Id;
                                        Category.Add(idCategory);
                                        List <int> listTechnology = new List <int>();
                                        foreach (var item in groupItem.Technologies)
                                        {
                                            item.CategoryId = idCategory;
                                            var resultTechnology = await _technologyService.InsertTechnology(item);

                                            int idTechnology = resultTechnology.Technology.Id;
                                            listTechnology.Add(idTechnology);
                                        }
                                        SkillRequestModel skill = new SkillRequestModel
                                        {
                                            PersonId     = idPerson,
                                            CategoryId   = idCategory,
                                            TechnologyId = listTechnology
                                        };
                                        listSkill.Add(skill);
                                    }
                                    if (listSkill.Count > 0)
                                    {
                                        foreach (var item in listSkill)
                                        {
                                            await _skillService.InserSkill(item);
                                        }
                                    }
                                }
                                List <Project> projects = ImportFileHandling.GetListProject(list, idPerson);
                                if (projects != null)
                                {
                                    foreach (var gorupItem in projects)
                                    {
                                        List <ProjectTechnology> projectTechnologies = new List <ProjectTechnology>();
                                        var resultProject = await _projectService.InsertProject(gorupItem);

                                        int idProject = resultProject.Project.Id;
                                        foreach (var item in gorupItem.Technologies)
                                        {
                                            ProjectTechnology projectTechnology = new ProjectTechnology
                                            {
                                                ProjectId    = idProject,
                                                TechnologyId = await _technologyService.GetTechnologyByPersonAndNameAsync(idPerson, item.Name)
                                            };
                                            projectTechnologies.Add(projectTechnology);
                                        }
                                        await _projectTechnologyService.InsertListTechnologyAsync(projectTechnologies);
                                    }
                                }
                            }
                            txScope.Complete();
                        }
                    }
                    catch
                    {
                        appResult.Result  = false;
                        appResult.Message = "CV Import Failed, file is invalid!";
                    }
                }
                else
                {
                    appResult.Result  = false;
                    appResult.Message = resultCheckFile.Message;
                }
            }
            else
            {
                appResult.Result  = false;
                appResult.Message = "CV Import Failed, file is invalid!";
            }
            return(appResult);
        }