Пример #1
0
        public IHttpActionResult Put(int id, OrgSchema value)
        {
            if (value == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            OrgSchemaHelper orgSchemaHelper = new OrgSchemaHelper(db);

            //if (!OrgMgmtDBHelper.isOrgSchemaExists(id, db))
            if (!orgSchemaHelper.isObjectExists(id))
            {
                return(NotFound());
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                //if (!OrgMgmtDBHelper.isOrgSchemaExists(id, db))
                if (!orgSchemaHelper.isObjectExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult Post([FromUri] int orgSchemaId,
                                      [FromUri] int bizEntityParentId, BizEntity value)
        {
            var bizEntityParent = db.bizEntities.Find(bizEntityParentId);

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

            var orgSchemaHelper = new OrgSchemaHelper(db);

            //if (!OrgMgmtDBHelper.isOrgSchemaExists(orgSchemaId, db) ||
            if (!orgSchemaHelper.isObjectExists(orgSchemaId) ||
                (bizEntityParentId > 0 && bizEntityParent == null))
            {
                ModelState.AddModelError(
                    string.Empty,
                    "数据错误(invalid orgSchemaId or bizEntityParentId>0 && bizEntityParent==null)!");
                return(BadRequest(ModelState));
            }

            var bizEntityHelper = new BizEntityHelper(db);

            try
            {
                //OrgMgmtDBHelper.saveCreatedBizEntity(
                //  db.orgSchemas.Find(orgSchemaId), value, bizEntityParent, db);
                bizEntityHelper.saveCreatedObject(db.orgSchemas.Find(orgSchemaId), value, bizEntityParent);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(bizEntityHelper.convert2DTO(value)));
        }