/// <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); }