/// <summary> /// 更新值设置 /// </summary> /// <param name="model"></param> /// <returns></returns> public BaseResult UpdateItemStandVal(ItemStandVal model) { BaseResult br = new BaseResult() { Succeeded = true }; try { using (CRDatabase _context = new CRDatabase()) { var entity = _context.HR_ITEMSTANDVAL.FirstOrDefault(p => p.ID == model.ID); if (entity != null) { entity.NAMEENG = model.NAMEENG; entity.EDITDATETIME = model.EDITDATETIME; entity.EDITUSERID = model.EDITUSERID; entity.MINVALUE = model.MINVALUE; entity.ITEMMAXVALUE = model.MAXVALUE; entity.UNIT = model.UNIT; _context.Entry(entity).State = EntityState.Modified; _context.SaveChanges(); //_context.Entry(ModelToEntity(model)).State = EntityState.Modified; //_context.SaveChanges(); } } } catch (Exception e) { br.Succeeded = false; br.Error = e.Message.ToString(); } return(br); }
/// <summary> /// 添加值设置 /// </summary> /// <param name="model"></param> /// <returns></returns> public BaseResult AddItemStandVal(ItemStandVal model) { BaseResult br = new BaseResult() { Succeeded = true }; using (CRDatabase _context = new CRDatabase()) { bool flag = !_context.HR_ITEMSTANDVAL.Any(p => p.ITEMNO == model.ITEMNO && p.ISDELETED == "0"); if (flag) { try { _context.HR_ITEMSTANDVAL.Add(ModelToEntity(model)); _context.SaveChanges(); } catch (Exception e) { br.Succeeded = false; br.Error = e.Message.ToString(); throw; } } else { br.Succeeded = false; br.Error = "该项已添加标准值返回,请检查"; } } return(br); }
/// <summary> /// Entity转Model /// </summary> /// <param name="entity"></param> /// <returns></returns> public ItemStandVal EntityToModel(HR_ITEMSTANDVAL entity) { if (entity != null) { var model = new ItemStandVal() { ID = entity.ID, ITEMNO = entity.ITEMNO, NAMEENG = entity.NAMEENG, MINVALUE = entity.MINVALUE, MAXVALUE = entity.ITEMMAXVALUE, UNIT = entity.UNIT, CREATEUSERID = entity.CREATEUSERID, CREATEDATETIME = entity.CREATEDATETIME, EDITUSERID = entity.EDITUSERID, EDITDATETIME = entity.EDITDATETIME, ISDELETED = entity.ISDELETED, OWNERID = entity.OWNERID }; return(model); } return(null); }
public HR_ITEMSTANDVAL ModelToEntity(ItemStandVal model) { if (model != null) { var entity = new HR_ITEMSTANDVAL() { ID = model.ID, ITEMNO = model.ITEMNO, NAMEENG = model.NAMEENG, MINVALUE = model.MINVALUE, ITEMMAXVALUE = model.MAXVALUE, UNIT = model.UNIT, CREATEUSERID = model.CREATEUSERID, CREATEDATETIME = model.CREATEDATETIME, EDITUSERID = model.EDITUSERID, EDITDATETIME = model.EDITDATETIME, ISDELETED = model.ISDELETED, OWNERID = model.OWNERID }; return(entity); } return(null); }