public async Task <IHttpActionResult> AddChemistryRoom(ChemistryIntDto chemistryIntDto) { try { ChemistryRoom chemistryRoom = new ChemistryRoom { Id = IdentityManager.NewId(), ChemistryId = chemistryIntDto.ChemistryId, User_id = chemistryIntDto.User_id, EntrepotId = chemistryIntDto.EntrepotId, RawNumber = chemistryIntDto.RawNumber, RawOutNumber = chemistryIntDto.RawOutNumber, Warning_RawNumber = chemistryIntDto.Warning_RawNumber, RoomDes = chemistryIntDto.RoomDes, }; db.ChemistryRooms.Add(chemistryRoom); if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "添加成功" })); } return(Json(new { code = 201, msg = "添加失败" })); } catch (Exception) { throw; } }
public async Task <IHttpActionResult> RemoveChemistryRoom(ChemistryIntDto chemistryIntDto) { try { if (chemistryIntDto.del_Id != null) { foreach (var item in chemistryIntDto.del_Id) { var result = new ChemistryRoom { Id = item }; // var result = Task.Run(() => (db.Z_Office.AsNoTracking().FirstOrDefault(m => m.Id == item))); db.Entry(result).State = System.Data.Entity.EntityState.Deleted; } 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; } }
public async Task <IHttpActionResult> AddChemistry(Z_ChemistryDto z_ChemistryDto) { try { var userId = ((UserIdentity)User.Identity).UserId; Z_Chemistry z_Chemistry = new Z_Chemistry { Id = IdentityManager.NewId(), Name = z_ChemistryDto.Name, Encoding = z_ChemistryDto.Encoding, EntryPersonId = z_ChemistryDto.EntryPersonId, Desc = z_ChemistryDto.Desc, Z_ChemistryTypeid = z_ChemistryDto.Z_ChemistryTypeid, EnglishName = z_ChemistryDto.EnglishName, Abbreviation = z_ChemistryDto.Abbreviation, BeCommonlyCalled1 = z_ChemistryDto.BeCommonlyCalled1, BeCommonlyCalled2 = z_ChemistryDto.BeCommonlyCalled2, CASNumber = z_ChemistryDto.CASNumber, MolecularWeight = z_ChemistryDto.MolecularWeight, MolecularFormula = z_ChemistryDto.MolecularFormula, StructuralFormula = z_ChemistryDto.StructuralFormula, Density = z_ChemistryDto.Density, CompanyId = z_ChemistryDto.Companyid, Statement = z_ChemistryDto.Statement, Caution = z_ChemistryDto.Caution, Number = z_ChemistryDto.Number, AppearanceState = z_ChemistryDto.AppearanceState, WarehousingTypeId = z_ChemistryDto.WarehousingTypeId, }; db.Z_Chemistry.Add(z_Chemistry); var result = await Task.Run(() => db.Entrepots.AsNoTracking().FirstOrDefaultAsync(p => p.Id > 0)); ChemistryRoom chemistryRoom = new ChemistryRoom { Id = IdentityManager.NewId(), ChemistryId = z_Chemistry.Id, RawNumber = 0, User_id = userId, EntrepotId = result.Id }; db.ChemistryRooms.Add(chemistryRoom); if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "添加成功" })); } else { return(Json(new { code = 400, msg = "添加失败" })); } } catch (Exception ex) { throw; } }
public async Task <IHttpActionResult> EditChemistryRoom(ChemistryIntDto chemistryIntDto) { try { var ChemistryRoom = new ChemistryRoom { Id = chemistryIntDto.Id }; db.Entry(ChemistryRoom).State = System.Data.Entity.EntityState.Unchanged; if (chemistryIntDto.ChemistryId != null) { ChemistryRoom.ChemistryId = chemistryIntDto.ChemistryId; } if (chemistryIntDto.User_id != null) { ChemistryRoom.User_id = chemistryIntDto.User_id; } if (chemistryIntDto.EntrepotId != null) { chemistryIntDto.EntrepotId = chemistryIntDto.EntrepotId; } if (chemistryIntDto.RawNumber != null) { ChemistryRoom.RawNumber = chemistryIntDto.RawNumber; } if (chemistryIntDto.RawOutNumber != null) { ChemistryRoom.RawOutNumber = chemistryIntDto.RawOutNumber; } if (chemistryIntDto.Warning_RawNumber != null) { ChemistryRoom.Warning_RawNumber = chemistryIntDto.Warning_RawNumber; } if (!string.IsNullOrWhiteSpace(chemistryIntDto.RoomDes)) { ChemistryRoom.RoomDes = chemistryIntDto.RoomDes; } if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "修改成功" })); } return(Json(new { code = 201, msg = "修改失败" })); } catch (Exception) { throw; } }
public async Task <IHttpActionResult> RemoveChemistry(Z_ChemistryDto z_ChemistryDto) { try { if (z_ChemistryDto.del_Id != null) { foreach (var item in z_ChemistryDto.del_Id) { var result = new Z_Chemistry { Id = item }; // var result = Task.Run(() => (db.Z_Office.AsNoTracking().FirstOrDefault(m => m.Id == item))); db.Entry(result).State = System.Data.Entity.EntityState.Unchanged; result.del_or = 1; var resul = new ChemistryRoom { ChemistryId = item }; var res = await db.ChemistryRooms.SingleOrDefaultAsync(s => s.ChemistryId == item); if (res != null) { res.RawNumber = 10; res.RawOutNumber = 0; res.Warning_RawNumber = 0; } } 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; } }