/// <summary> /// Create Technology /// </summary> /// <param name="technology"></param> /// <returns></returns> public async Task <TechnologyViewModel> InsertTechnology(Technology technology) { model.AppResult.Result = false; if (technology.CategoryId <= 0) { model.AppResult.Message = Constants.Constant.ID_ERROR; } else if (String.IsNullOrEmpty(technology.Name) || technology.Name.Length > 2555) { model.AppResult.Message = Constants.Constant.NAME_ERROR; } else { technology.CreatedBy = WebAPI.Helpers.HttpContext.CurrentUser; technology.UpdatedBy = WebAPI.Helpers.HttpContext.CurrentUser; technology.CreatedAt = DateTime.Now; technology.UpdatedAt = DateTime.Now; var modelCategory = await _categoryRepository.FindAsync(technology.CategoryId); if (modelCategory == null) { model.AppResult.Message = "Create failure, Category not exists"; } else { var checkTechnology = await _technologyRepository.CheckTechnologyAsync(technology); if (checkTechnology != null) { model.AppResult.Message = "Create failure, Technology already exists"; model.Technology.Id = checkTechnology.Id; } else { var id = await _technologyRepository.InsertAsync(technology); Technology modelTechnology = await _technologyRepository.FindAsync(id); TechnologyResource resultModel = new TechnologyResource(); if (modelTechnology != null) { model.Technology.Id = modelTechnology.Id; resultModel.Id = modelTechnology.Id; resultModel.Name = modelTechnology.Name; resultModel.CreatedAt = modelTechnology.CreatedAt; resultModel.CategoryId = modelTechnology.Category.Id; resultModel.CategoryName = modelTechnology.Category.Name; } if (resultModel != null) { model.AppResult.DataResult = resultModel; } model.AppResult.Result = true; model.AppResult.Message = Constants.Constant.INSERT_SUCCESS; } } } return(model); }
/// <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); }