public async Task <IHttpActionResult> AddFnishedProduct(Z_FnishedProductDto z_FnishedProductDto) { try { var userId = ((UserIdentity)User.Identity).UserId; Z_FnishedProduct z_FnishedProduct = new Z_FnishedProduct { Id = IdentityManager.NewId(), Name = z_FnishedProductDto.Name, Encoding = z_FnishedProductDto.Encoding, EntryPersonId = z_FnishedProductDto.EntryPersonId, CompanyId = z_FnishedProductDto.Companyid, Desc = z_FnishedProductDto.Desc, Z_FinshedProductTypeid = z_FnishedProductDto.Z_FinshedProductTypeid, Finshed_Sign = z_FnishedProductDto.Finshed_Sign, EnglishName = z_FnishedProductDto.EnglishName, Abbreviation = z_FnishedProductDto.Abbreviation, BeCommonlyCalled1 = z_FnishedProductDto.BeCommonlyCalled1, BeCommonlyCalled2 = z_FnishedProductDto.BeCommonlyCalled2, CASNumber = z_FnishedProductDto.CASNumber, MolecularWeight = z_FnishedProductDto.MolecularWeight, MolecularFormula = z_FnishedProductDto.MolecularFormula, StructuralFormula = z_FnishedProductDto.StructuralFormula, Density = z_FnishedProductDto.Density, Statement = z_FnishedProductDto.Statement, Number = z_FnishedProductDto.Number, Caution = z_FnishedProductDto.Caution, AppearanceState = z_FnishedProductDto.AppearanceState, WarehousingTypeId = z_FnishedProductDto.WarehousingTypeId, }; var result = await Task.Run(() => db.Entrepots.AsNoTracking().FirstOrDefaultAsync(p => p.Id > 0)); FnishedProductRoom fnishedProductRoom = new FnishedProductRoom { Id = IdentityManager.NewId(), FnishedProductId = z_FnishedProduct.Id, User_id = userId, RawNumber = 0, EntrepotId = result.Id }; db.FnishedProductRooms.Add(fnishedProductRoom); db.Z_FnishedProduct.Add(z_FnishedProduct); 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> RemoveFnishedProduct(Z_FnishedProductDto z_FnishedProductDto) { try { if (z_FnishedProductDto.del_Id != null) { foreach (var item in z_FnishedProductDto.del_Id) { var result = new Z_FnishedProduct { Id = item }; db.Entry(result).State = System.Data.Entity.EntityState.Unchanged; result.del_or = 1; // var resul = new FnishedProductRoom { FnishedProductId = item }; var res = await db.FnishedProductRooms.SingleOrDefaultAsync(s => s.FnishedProductId == 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; } }
public async Task <IHttpActionResult> EditFnishedProduct(Z_FnishedProductDto z_FnishedProductDto) { try { if (ModelState.IsValid) { var type = new Models.Db.Aggregate.FinancialManagement.WarehouseManagements.Z_FnishedProduct() { Id = z_FnishedProductDto.Id }; db.Entry(type).State = System.Data.Entity.EntityState.Unchanged; // Z_RawDto z_RawDto1 = new Z_RawDto(); if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Name)) { type.Name = z_FnishedProductDto.Name; } if (z_FnishedProductDto.Number != null) { type.Number = z_FnishedProductDto.Number; } if (z_FnishedProductDto.Companyid != null) { type.CompanyId = z_FnishedProductDto.Companyid; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Encoding)) { type.Encoding = z_FnishedProductDto.Encoding; } if (z_FnishedProductDto.EntryPersonId != null) { type.EntryPersonId = z_FnishedProductDto.EntryPersonId; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Desc)) { type.Desc = z_FnishedProductDto.Desc; } if (z_FnishedProductDto.Z_FinshedProductTypeid != null) { type.Z_FinshedProductTypeid = z_FnishedProductDto.Z_FinshedProductTypeid; } if (z_FnishedProductDto.Finshed_Sign != null) { type.Finshed_Sign = z_FnishedProductDto.Finshed_Sign; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.EnglishName)) { type.EnglishName = z_FnishedProductDto.EnglishName; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Abbreviation)) { type.Abbreviation = z_FnishedProductDto.Abbreviation; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.BeCommonlyCalled1)) { type.BeCommonlyCalled1 = z_FnishedProductDto.BeCommonlyCalled1; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.BeCommonlyCalled2)) { type.BeCommonlyCalled2 = z_FnishedProductDto.BeCommonlyCalled2; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.CASNumber)) { type.CASNumber = z_FnishedProductDto.CASNumber; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.MolecularWeight)) { type.MolecularWeight = z_FnishedProductDto.MolecularWeight; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.MolecularFormula)) { type.MolecularFormula = z_FnishedProductDto.MolecularFormula; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.StructuralFormula)) { type.StructuralFormula = z_FnishedProductDto.StructuralFormula; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Density)) { type.Density = z_FnishedProductDto.Density; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Statement)) { type.Statement = z_FnishedProductDto.Statement; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.Caution)) { type.Caution = z_FnishedProductDto.Caution; } if (!string.IsNullOrWhiteSpace(z_FnishedProductDto.AppearanceState)) { type.AppearanceState = z_FnishedProductDto.AppearanceState; } if (z_FnishedProductDto.WarehousingTypeId != null) { type.WarehousingTypeId = z_FnishedProductDto.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; } }