public IHttpActionResult Post([FromUri] int bizEntitySchemaId, [FromUri] int departmentParentId, Department value) { var departmentParent = db.departments.Find(departmentParentId); if (value == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db); if (!bizEntitySchemaHelper.isObjectExists(bizEntitySchemaId) || (departmentParentId > 0 && departmentParent == null)) { return(BadRequest("数据错误!")); } DepartmentHelper departmentHelper = new DepartmentHelper(db); try { departmentHelper.saveCreatedObject( db.bizEntitySchemas.Find(bizEntitySchemaId), value, departmentParent); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok(departmentHelper.convert2DTO(value))); }
public void saveCreatedObject_validObj_willExists(SchemeMode schemeMode) { OrgMgmtDBHelper.schemeMode = schemeMode; BizEntityHelper o = new BizEntityHelper(db); BizEntity bizEntity = o.createObject(); bizEntity.name = "Integration_Test_XXXYYYZZZ"; OrgSchema orgSchema = db.orgSchemas.FirstOrDefault(); BizEntity bizParentEntity = orgSchema. bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild; o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity); BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db); BizEntitySchema bizEntitySchema = new BizEntitySchema(); bizEntitySchema.BizEntity = bizEntity; bizEntitySchemaHelper.saveCreatedObject(bizEntitySchema); Assert.True(bizEntitySchemaHelper.isObjectExists(bizEntitySchema.bizEntitySchemaId)); }
public IHttpActionResult Put(int id, BizEntitySchema value) { if (value == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != value.bizEntitySchemaId) { return(BadRequest()); } BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db); if (!bizEntitySchemaHelper.isObjectExists(id)) { return(NotFound()); } try { if (!bizEntitySchemaHelper.isObjectChangeAllowed(id, value)) { return(BadRequest("不允许修改对象!")); } ; } catch (Exception ex) { return(BadRequest(ex.Message)); } db.Entry(value).State = EntityState.Modified; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }