public ProjectModel Get(string Id) { var datebase = _context.DevopsProject; var model = datebase.Where(d => d.Id == Id).FirstOrDefault(); var res = new ProjectModel() { }; if (null != model) { ModelBindGenericClass <DevopsProject, ProjectModel> .ModelBind(model, res); } return(res); }
public async Task <ResponseBaseModel> Update([FromBody] ProjectModel req) { var res = new ResponseBaseModel() { isSuccess = false }; bool updateWIki = false; if (null != req) { var datebase = _context.DevopsProject; var project = datebase.Where(m => m.Id == req.Id).FirstOrDefault(); try { if (null != project) { // 内容更新 project.Manager = req.manager; project.Priority = req.priority; project.StartTime = req.startTime; project.EndTime = req.endTime; project.Team = req.team; project.Client = req.client; project.State = req.state; if (project.Description != req.description) { project.Description = req.description; updateWIki = true; } datebase.Update(project); } else { updateWIki = true; var newProject = new DevopsProject() { }; // 插入新的 ModelBindGenericClass <ProjectModel, DevopsProject> .ModelBind(req, newProject); // 设置order var min = datebase.Min(d => d.Order); newProject.Order = min - _baseNumber; datebase.Add(newProject); } // 提交 _context.SaveChanges(); res.isSuccess = true; // 不显示调用wiki结果 if (updateWIki) { // 同步wiki string url = $"{_configuration.GetSection("Urls").GetSection("DevOps").Value}/api/Project/SendWiki"; // projectGuid={req.Id}&content={req.description} string wikiReq = JsonConvert.SerializeObject(new { projectGuid = req.Id, content = req.description }); using (var client = _httpClientFactory.CreateClient()) { HttpContent httpContent = new StringContent(wikiReq, Encoding.UTF8); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await client.PostAsync(url, httpContent); var wikiRes = await response.Content.ReadAsStringAsync(); // wiki 同步结果不显示 } } } catch (Exception ex) { res.message = $"更新发生意外错误,{ex.Message}"; } } else { res.message = "请求参数不为空"; } return(res); }