public async Task <IActionResult> PutBMaterial([FromRoute] int id, [FromBody] BMaterial bMaterial) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bMaterial.MatId) { return(BadRequest()); } _context.Entry(bMaterial).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BMaterialExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ContentResult Update() { ResultData <string> rt = new ResultData <string>(); BMaterial u = GetUpdate <BMaterial>(); //非空验证和属性格式验证 string msg = mService.CheckMaterial(u); if (!string.IsNullOrEmpty(msg)) { rt.message = msg; rt.status = -1; return(ReturnResult(rt)); } //验证用户是否存在 if (mService.IsNotExits(u, false)) { u.UpdateDate = DateTime.Now; u.UpdateBy = this.CurrentUser.ID; mService.UpdateMaterial(u); } else { rt.status = -1; rt.message = "用户编码已经存在."; } return(ReturnResult(rt)); }
public async Task <IActionResult> PostBMaterial([FromBody] BMaterial bMaterial) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BMaterial.Add(bMaterial); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBMaterial", new { id = bMaterial.MatId }, bMaterial)); }
public ContentResult Delete() { ResultData <string> rt = new ResultData <string>(); //获取前台传会的删除ID BMaterial user = GetDelete <BMaterial>(); mService.RemoveMaterial(user); rt.message = "删除成功."; return(ReturnResult(rt)); }
/// <summary> /// 检查非空验证 /// </summary> /// <param name="Material"></param> public string CheckMaterial(BMaterial material) { string msg = string.Empty; if (string.IsNullOrWhiteSpace(material.MaterialCode)) { msg = "物料编码不能为空."; return(msg); } if (string.IsNullOrWhiteSpace(material.MaterialName)) { msg = "物料名称不能为空."; return(msg); } return(msg); }
/// <summary> /// 读取单元信息表1 /// </summary> public void ReadElem1(Worksheet Esheet0, ref Bmodel MyModel) { int iFrow = Esheet0.Cells.FirstRowIndex; int iLrow = Esheet0.Cells.LastRowIndex; //材料信息读取 for (int i = iFrow + 1; i <= iLrow; i++) { Row CurRow = Esheet0.Cells.GetRow(i); int imat = int.Parse(CurRow.GetCell(4).StringValue); //材料性质id string Cursec = CurRow.GetCell(7).StringValue; //截面名称 int iele = int.Parse(CurRow.GetCell(0).StringValue); int ieleI = int.Parse(CurRow.GetCell(1).StringValue); int ieleJ = int.Parse(CurRow.GetCell(2).StringValue); int MaxProp = MyModel.sections.Count > 0 ? MyModel.sections.Keys.Max() : 0; //记录最大截面号 int iProp = 1; //当前截面号 bool hasSec = false; //指示是否有当前截面 BMaterial mat = new BMaterial(imat, MatType.USER, "Mat_" + imat.ToString()); foreach (KeyValuePair <int, BSections> ss in MyModel.sections) { if (ss.Value.Name == Cursec) { iProp = ss.Key; hasSec = true;//有当前截面 break; } } //如果没有当前截面,则添加一个新的截面 if (hasSec == false) { iProp = MaxProp + 1; //新的截面号 SectionGeneral sec = new SectionGeneral(iProp, Cursec); MyModel.AddSection(sec); //添加入库 } MyModel.AddMat(mat);//添加料号入库 //最后添加单元入数据库 FrameElement ee = new FrameElement(iele, ElemType.BEAM, imat, iProp, ieleI, ieleJ); MyModel.AddElement(ee); } }
/// <summary> /// 插入新物料 /// </summary> /// <param name="material"></param> /// <returns></returns> public int AddMaterial(BMaterial material) { object result = mRepository.Insert(material); return(Convert.ToInt32(result)); }
/// <summary> /// 物料是否存在 /// </summary> /// <param name="material"></param> /// <param name="isAdd"></param> public bool IsNotExits(BMaterial material, bool isAdd) { return(mRepository.IsNotExits(material, isAdd)); }
/// <summary> /// 更新物料 /// </summary> /// <param name="material"></param> /// <returns></returns> public bool UpdateMaterial(BMaterial material) { return(mRepository.Update(material)); }
/// <summary> /// 删除物料 /// </summary> /// <param name="material"></param> /// <returns></returns> public bool RemoveMaterial(BMaterial material) { //删除物料 return(mRepository.Delete(material)); }