// 获取输入框架 public TemplateSchemaInputDto GetTemplateSchemaInputDtoByTplId(int tplId, int[] specId) { var template = _tplRep.GetAll().Where(x => x.Id == tplId).Single(); List <TplSpecimen> tplSpecimenList = new List <TplSpecimen>(); if (specId.Count() == 0 || specId.Contains(-1)) { tplSpecimenList = _tplSpecRep.GetAll().Where(x => x.TplId == tplId) .OrderBy(x => x.TplId).ThenByDescending(x => x.OrderNum).ToList(); } else { tplSpecimenList = _tplSpecRep.GetAll().Where(x => specId.Contains(x.Id)) .OrderBy(x => x.TplId).ThenByDescending(x => x.OrderNum).ToList(); } var specIdList = tplSpecimenList.Select(x => x.Id).ToList(); List <TplElement> tplEleList = this._tplEleRep.GetAll().Where(x => specIdList.Contains(x.TplSpecId)) .OrderBy(x => x.TplSpecId).ThenBy(x => x.OrderNo).ToList(); List <SpecInputDto> tempSpecInputList = new List <SpecInputDto>(); foreach (var item in tplSpecimenList) { var tempEleList = tplEleList.Where(x => x.TplSpecId == item.Id).ToList(); List <ElementInputDto> tempEleInputList = new List <ElementInputDto>(); foreach (var ele in tempEleList) { ElementInputDto tempEleInput = new ElementInputDto(); tempEleInput.EleId = ele.Id; tempEleInput.SpecId = item.Id; tempEleInput.TplId = tplId; tempEleInput.UnitName = ele.UnitName; tempEleInput.EleName = ele.ElementName; tempEleInput.FormName = "ele" + ele.Id.ToString(); tempEleInput.IsVisible = true; tempEleInputList.Add(tempEleInput); } SpecInputDto tempSpecInput = new SpecInputDto(); tempSpecInput.SpecId = item.Id; tempSpecInput.SpecName = item.SpecName; tempSpecInput.EleList = tempEleInputList; tempSpecInput.FormName = "spe" + item.Id.ToString(); tempSpecInputList.Add(tempSpecInput); } TemplateSchemaInputDto retInput = new TemplateSchemaInputDto(); retInput.TplId = tplId; retInput.TplName = template.TplName; retInput.FormName = "for" + tplId.ToString(); retInput.SpecList = tempSpecInputList; return(retInput); }
public async Task UpdateElement(ElementInputDto input) { if (await db.Elements.AnyAsync(m => m.Name == input.Name && m.Id != input.ElementId)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该元素名称已存在" })) }); } var element = await db.Elements.SingleOrDefaultAsync(m => m.Id == input.ElementId); var menu = await db.Menus.SingleOrDefaultAsync(m => m.Id == input.MenuId); if (element != null && menu != null) { element.Key = menu.Key; element.DisplayOrder = input.DisplayOrder; element.MenuId = input.MenuId; element.Name = input.Name; element.Value = input.Value; } else { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = input.ElementId + "不存在或" + input.MenuId + "不存在" })) }); } if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }