示例#1
0
        public IHttpActionResult Post(BizEntitySchema value, [FromUri] int bizEntityId)
        {
            var bizEntityHelper = new BizEntityHelper(db);

            if (value == null || !ModelState.IsValid ||
                !bizEntityHelper.isObjectExists(bizEntityId))
            {
                return(BadRequest(ModelState));
            }

            var bizEntity = db.bizEntities.Find(bizEntityId);
            BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db);

            try
            {
                value.BizEntity = bizEntity;
                bizEntitySchemaHelper.saveCreatedObject(value);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(bizEntitySchemaHelper.convert2DTO(value)));
        }
示例#2
0
        public void saveCreatedObject_validObjWithNoParent_willExist()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema = db.orgSchemas.FirstOrDefault();

            o.saveCreatedObject(orgSchema, bizEntity, null);

            Assert.True(o.isObjectExists(bizEntity.bizEntityId));
            Assert.AreEqual(1, db.bizEntityRelationOnOrgSchemas.Where(
                                ber => ber.assistOrgSchemaId == orgSchema.orgSchemaId &&
                                ber.bizEntityIdChild == bizEntity.bizEntityId).Count());
        }
示例#3
0
        public IHttpActionResult Put(int id, BizEntity value)
        {
            if (value == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != value.bizEntityId)
            {
                return(BadRequest());
            }

            var bizEntityHelper = new BizEntityHelper(db);

            if (!bizEntityHelper.isObjectExists(id))
            {
                return(NotFound());
            }

            try
            {
                if (!bizEntityHelper.isObjectChangeAllowed(id, value))
                {
                    return(BadRequest("不允许修改对象!"));
                }
                ;
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            db.Entry(value).State = EntityState.Modified;

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }