public async Task <IActionResult> AddPipeLine([FromBody] PipeLineModel obj) { try { if (ModelState.IsValid) { ClaimsIdentity claimsIdentity = User.Identity as ClaimsIdentity; var currentLoginUserid = new UserClaims(claimsIdentity).LoggedInUserId; var currentLoginUserOrgid = new UserClaims(claimsIdentity).OrgId; var config = new MapperConfiguration(cfg => { cfg.CreateMap <PipeLineModel, PipeLineDTO>(); }); obj.OrgId = currentLoginUserOrgid; obj.CreatedBy = currentLoginUserid; IMapper mapperResponse = config.CreateMapper(); var pipelineDTO = mapperResponse.Map <PipeLineModel, PipeLineDTO>(obj); using (var uow = new UnitOfWork(_configs.Value.DbConnectionString)) { int result = await uow.PipeLine.AddUpdatePipeLine(pipelineDTO); uow.Commit(); if (result == 1) { return(BadRequest(new ApiResponse { message = ApiMessageConstants.pipeAlreadyExists })); } else if (result == 3) { return(Ok(new ApiResponse { message = ApiMessageConstants.pipeUpdated })); } return(Ok(new ApiResponse { message = ApiMessageConstants.pipeAdded, data = result })); } } else { return(BadRequest(new ApiResponse { message = ApiMessageConstants.someThingWentWrong })); } } catch (Exception ex) { return(BadRequest(new ApiResponse { message = ex.Message })); } }
// public async Task <List <PipeLineModel> > GetProjectPipeLines(string projectname) { List <PipeLineModel> pipelines = new List <PipeLineModel>(); PipeLineModel pipeLine = null; DevOpsConnectionPool poolObj = _builderPool.Get(); try { var buildclient = new BuildHttpClient(new Uri(poolObj.CollUrl), poolObj.VssCredentials); var result = await buildclient.GetDefinitionsAsync(projectname);//call after some time if (result != null && result.Count > 0) { foreach (var item in result) { pipeLine = new PipeLineModel(); pipeLine.Id = item.Id; pipeLine.Url = item.Url; pipeLine.Name = item.Name; pipeLine.Path = item.Path; pipelines.Add(pipeLine); } } else { pipelines.Add(new PipeLineModel() { Id = 0, Name = string.Empty, Path = string.Empty, Url = string.Empty });//just one dummy } } catch (Exception ) { pipelines.Add(new PipeLineModel() { Id = 0, Name = string.Empty, Path = string.Empty, Url = string.Empty });//just one dummy } finally { _builderPool.Return(poolObj); } return(pipelines); }