public async Task <IHttpActionResult> AddRowType(ChemistryTypeDto chemistryTypeDto) { try { if (!string.IsNullOrWhiteSpace(chemistryTypeDto.Name) && !string.IsNullOrWhiteSpace(chemistryTypeDto.Dec)) { Z_ChemistryType z_ChemistryType = new Z_ChemistryType { Id = IdentityManager.NewId(), Name = chemistryTypeDto.Name, Dec = chemistryTypeDto.Dec }; db.Z_ChemistryType.Add(z_ChemistryType); if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "添加成功" })); } else { return(Json(new { code = 400, msg = "添加失败" })); } } else { return(Json(new { code = 201, msg = "请勿添加空数据" })); } } catch (Exception ex) { throw; } }
public async Task <IHttpActionResult> RemoveRowType(ChemistryTypeDto chemistryTypeDto) { try { if (chemistryTypeDto.del_Id != null) { foreach (var item in chemistryTypeDto.del_Id) { var result = new Z_ChemistryType { Id = item }; db.Entry(result).State = System.Data.Entity.EntityState.Unchanged; result.IsDelete = true; // var result = db.Z_ChemistryType.AsNoTracking().First(m => m.Id == item); } if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "删除成功" })); } else { return(Json(new { code = 400, msg = "删除失败" })); } } else { return(Json(new { code = 201, msg = "请勿传递空数据" })); } } catch (Exception) { throw; } }