public IHttpActionResult PostRelationship(CategoryDictionary category, RelationshipModel <int, int> rels) { EmpContext content1 = new EmpContext(); var list = brandBLL.Filter(x => rels.PKS.Contains(x.Id)).ToList(); if (list.Count != rels.PKS.Count) { return(BadRequest("参数出错,部分品牌信息未找到,请审查后再提交")); } switch (category) { case CategoryDictionary.Meter: if (list.Count != 1) { return(BadRequest("参数出错,品牌参数只能一条,请审查后再提交")); } var brand = list.FirstOrDefault(); var meters = meterBLL.Filter(x => rels.FKS.Contains(x.Id)).ToList(); if (meters.Count != rels.FKS.Count) { return(BadRequest("参数出错,部分参数信息未找到,请审查后再提交")); } var obj = new JObject(); obj.Add("BrandId", brand.Id); meterBLL.Update(x => rels.FKS.Contains(x.Id), obj); //meterBLL.Update(x => rels.FKS.Contains(x.Id), new { BrandID = brand.Id }); break; case CategoryDictionary.Parameter: //var parameters = paramBLL.Filter(x => rels.FKS.Contains(x.Id)).ToList(); var dicts = dictBLL.Filter(x => x.Code == "Parameter" && rels.FKS.Contains(x.Id)).ToList(); if (dicts.Count != rels.FKS.Count) { return(BadRequest("参数出错,部分参数信息未找到,请审查后再提交")); } foreach (var brandId in list) { foreach (var param in rels.FKS) { Parameter parameters = new Parameter(); parameters.BrandId = brandId.Id; parameters.TypeId = param; parameters.Unit = dicts.Where(x => x.Id == param).FirstOrDefault().EquText; content1.Parameters.Add(parameters); } } content1.SaveChanges(); content1.Dispose(); //return BadRequest("系统暂不支持此功能"); break; case CategoryDictionary.Building: case CategoryDictionary.BuidlingCategory: case CategoryDictionary.MeterType: case CategoryDictionary.Brand: case CategoryDictionary.Organization: case CategoryDictionary.Manager: case CategoryDictionary.Role: case CategoryDictionary.Permission: default: return(BadRequest("系统不支持此功能")); break; } return(Ok()); }