public ProjectCreateResponse Create(ProjectCreateRequest request) { ProjectCreateResponse response = new ProjectCreateResponse(); ProjectEntity entityToInsert = ToEntity(request.Project); using (var sqliteConn = ConnectionProvider.GetSqliteConn()) { var count = sqliteConn.QuerySingle <int>("select count(1) from project where Name = @Name", new { Name = request.Project.Name }); if (count > 0) { response.Message = "应用名称已存在"; return(response); } } using (var sqliteConn = ConnectionProvider.GetSqliteConn()) { sqliteConn.Execute("insert into project(Name, Description, Repository, Params, TemplateName, DataStatus, CreateBy, CreateTime, LastUpdateBy, LastUpdateTime) values (@Name, @Description, @Repository, @Params, @TemplateName, @DataStatus, @CreateBy, @CreateTime, @LastUpdateBy, @LastUpdateTime)", entityToInsert); } response.Status = 1; return(response); }
public ProjectCreate(ProjectCreateRequest request) { if (request != null) { if (string.IsNullOrWhiteSpace(request.Name)) { Response = new ProjectCreateResponse { Type = ProjectCreateResponseType.NameEmpty }; return; } using (var dbContext = new ApplicationDbContext()) { if (dbContext.Projects.Any(aProject => aProject.Name.ToLower().Trim() == request.Name.ToLower().Trim())) { Response = new ProjectCreateResponse { Type = ProjectCreateResponseType.NameExists }; return; } var projectNameWords = request.Name.Split(' '); var projectKey = projectNameWords.Count() > 0 ? string.Join("", projectNameWords.Select(aWord => aWord[0])) : projectNameWords.Take(3).ToString(); if (dbContext.Projects.Any(aProject => aProject.Key == projectKey.ToUpper().Trim())) { throw new NotImplementedException(); } var project = new Project(); project.Set(request, projectKey); dbContext.Projects.Add(project); dbContext.SaveChanges(); Response = new ProjectCreateResponse { Identifier = project.Identifier, Type = ProjectCreateResponseType.Success, }; } } }
public async Task <ProjectCreateResponse> CreateProject(ProjectCreateRequest request) { var response = new ProjectCreateResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (!currentUser.IsAdmin) { response.SetInvalid(); return(response); } if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive)) { response.SetInvalidBecauseParentNotActive(); return(response); } if (await _projectRepository.Any(x => x.Name == request.ProjectName && x.OrganizationId == currentUser.OrganizationId)) { response.ErrorMessages.Add("project_name_must_be_unique"); response.Status = ResponseStatus.Failed; return(response); } var entity = _projectFactory.CreateEntityFromRequest(request, currentUser.Organization); var uowResult = await _projectUnitOfWork.DoCreateWork(request.CurrentUserId, entity); if (uowResult) { response.Item = _projectFactory.CreateDtoFromEntity(entity); response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }