public async Task <IHttpActionResult> EditRow(Z_RawDto z_RawDto) { try { if (ModelState.IsValid) { var type = new Models.Db.Aggregate.FinancialManagement.WarehouseManagements.Z_Raw() { Id = z_RawDto.Id }; db.Entry(type).State = System.Data.Entity.EntityState.Unchanged; // Z_RawDto z_RawDto1 = new Z_RawDto(); if (!string.IsNullOrWhiteSpace(z_RawDto.Name)) { type.Name = z_RawDto.Name; } if (z_RawDto.Number != null) { type.Number = z_RawDto.Number; } if (z_RawDto.Companyid != null) { type.CompanyId = z_RawDto.Companyid; } if (!string.IsNullOrWhiteSpace(z_RawDto.Encoding)) { type.Encoding = z_RawDto.Encoding; } if (z_RawDto.EntryPersonId != null) { type.EntryPersonId = z_RawDto.EntryPersonId; } if (!string.IsNullOrWhiteSpace(z_RawDto.Desc)) { type.Desc = z_RawDto.Desc; } if (z_RawDto.Z_RowTypeid != null) { type.Z_RowTypeid = z_RawDto.Z_RowTypeid; } if (!string.IsNullOrWhiteSpace(z_RawDto.EnglishName)) { type.EnglishName = z_RawDto.EnglishName; } if (!string.IsNullOrWhiteSpace(z_RawDto.Abbreviation)) { type.Abbreviation = z_RawDto.Abbreviation; } if (!string.IsNullOrWhiteSpace(z_RawDto.BeCommonlyCalled1)) { type.BeCommonlyCalled1 = z_RawDto.BeCommonlyCalled1; } if (!string.IsNullOrWhiteSpace(z_RawDto.BeCommonlyCalled2)) { type.BeCommonlyCalled2 = z_RawDto.BeCommonlyCalled2; } if (!string.IsNullOrWhiteSpace(z_RawDto.CASNumber)) { type.CASNumber = z_RawDto.CASNumber; } if (!string.IsNullOrWhiteSpace(z_RawDto.MolecularWeight)) { type.MolecularWeight = z_RawDto.MolecularWeight; } if (!string.IsNullOrWhiteSpace(z_RawDto.MolecularFormula)) { type.MolecularFormula = z_RawDto.MolecularFormula; } if (!string.IsNullOrWhiteSpace(z_RawDto.StructuralFormula)) { type.StructuralFormula = z_RawDto.StructuralFormula; } if (!string.IsNullOrWhiteSpace(z_RawDto.Density)) { type.Density = z_RawDto.Density; } if (!string.IsNullOrWhiteSpace(z_RawDto.Statement)) { type.Statement = z_RawDto.Statement; } if (!string.IsNullOrWhiteSpace(z_RawDto.Caution)) { type.Caution = z_RawDto.Caution; } if (!string.IsNullOrWhiteSpace(z_RawDto.AppearanceState)) { type.AppearanceState = z_RawDto.AppearanceState; } if (z_RawDto.WarehousingTypeId != null) { type.WarehousingTypeId = z_RawDto.WarehousingTypeId; } if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "修改成功" })); } else { return(Json(new { code = 200, msg = "修改失败" })); } } else { return(Json(new { code = 201, msg = "请勿修改空数据" })); } } catch (Exception) { throw; } }
public async Task <IHttpActionResult> AddRow(Z_RawDto z_RawDto) { try { string Moren = " N / A"; Z_Raw z_Raw = new Z_Raw { Id = IdentityManager.NewId(), Name = z_RawDto.Name, Encoding = z_RawDto.Encoding != null? z_RawDto.Encoding: Moren, EntryPersonId = z_RawDto.EntryPersonId, Desc = z_RawDto.Desc, CompanyId = z_RawDto.Companyid, Z_RowTypeid = z_RawDto.Z_RowTypeid, EnglishName = z_RawDto.EnglishName != null? z_RawDto.EnglishName: Moren, Abbreviation = z_RawDto.Abbreviation != null ? z_RawDto.Abbreviation : Moren, BeCommonlyCalled1 = z_RawDto.BeCommonlyCalled1 != null ? z_RawDto.BeCommonlyCalled1 : Moren, BeCommonlyCalled2 = z_RawDto.BeCommonlyCalled2 != null ? z_RawDto.BeCommonlyCalled2 : Moren, CASNumber = z_RawDto.CASNumber != null ? z_RawDto.CASNumber : Moren, MolecularWeight = z_RawDto.MolecularWeight != null ? z_RawDto.MolecularWeight : Moren, MolecularFormula = z_RawDto.MolecularFormula, StructuralFormula = z_RawDto.StructuralFormula, Density = z_RawDto.Density, Number = z_RawDto.Number, Statement = z_RawDto.Statement != null ? z_RawDto.Statement : Moren, Caution = z_RawDto.Caution != null ? z_RawDto.Caution : Moren, AppearanceState = z_RawDto.AppearanceState != null ? z_RawDto.AppearanceState : Moren, WarehousingTypeId = z_RawDto.WarehousingTypeId, }; var result = await Task.Run(() => db.Entrepots.AsNoTracking().FirstOrDefaultAsync(p => p.Id > 0)); // var results = await Task.Run(() => db.RawRooms.AsNoTracking().Where(p => p.RawId == z_Raw.Id).ToListAsync()); //foreach (var item in result) //{ // if (results==null) // { // this.EntrepotId = item.Id; // break; // } //} var userId = ((UserIdentity)User.Identity).UserId; RawRoom rawRoom = new RawRoom { Id = IdentityManager.NewId(), RawId = z_Raw.Id, RawNumber = 0, User_id = userId, EntrepotId = result.Id }; db.RawRooms.Add(rawRoom); db.Z_Raw.Add(z_Raw); if (await db.SaveChangesAsync() > 0) { return(Json(new { code = 200, msg = "添加成功" })); } else { return(Json(new { code = 400, msg = "添加失败" })); } } catch (Exception) { throw; } }
public async Task <IHttpActionResult> RemoveRow(Z_RawDto z_RawDto) { try { if (z_RawDto.del_Id != null) { foreach (var item in z_RawDto.del_Id) { var result = new Z_Raw { Id = item }; db.Entry(result).State = System.Data.Entity.EntityState.Unchanged; result.del_or = 1; //var resul = new RawRoom { RawId = item }; //db.Entry(resul).State = System.Data.Entity.EntityState.Unchanged; var res = await db.RawRooms.SingleOrDefaultAsync(s => s.RawId == 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 = "删除成功" })); } return(Json(new { code = 201, msg = "删除失败;" })); ////[Pursh_User] ////var Presud = new Purchase { RawId = item }; ////db.Entry(Presud).State = System.Data.Entity.EntityState.Deleted; ////var PresudU = new Pursh_User { Purchase_Id = Presud.Id }; ////db.Entry(PresudU).State = System.Data.Entity.EntityState.Deleted; ////优化的地方 //using (XiAnOuDeContext db = new XiAnOuDeContext()) { // var reltp = await Task.Run(() => db.RawRooms.SingleOrDefaultAsync(p => p.RawId == item)); // db.RawRooms.Remove(reltp); // await db.SaveChangesAsync(); // // var resud = new RawRoom { RawId = item }; // // db.Entry(resud).State = System.Data.Entity.EntityState.Deleted; //} //using (XiAnOuDeContext db = new XiAnOuDeContext()) //{ // var relt = await Task.Run(() => db.Z_Raw.SingleOrDefaultAsync(p => p.Id == item)); // db.Z_Raw.Remove(relt); // db.Entry(result).State = System.Data.Entity.EntityState.Deleted; } else { return(Json(new { code = 201, msg = "请勿传递空数据" })); } } catch (Exception) { throw; } }