Пример #1
0
        public IHttpActionResult Patch([FromODataUri] string key, Delta <PerioperativeEntity> patch)
        {
            PerioperativeService service = new PerioperativeService();
            object id;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else if (patch.GetChangedPropertyNames().Contains("ID") && patch.TryGetPropertyValue("ID", out id) && (string)id != key)
            {
                return(BadRequest("The key from the url must match the key of the entity in the body"));
            }
            try
            {
                var query = service.GetEntity(key.ToString());
                patch.Patch(query);
                service.UpdateEntity(query);
                return(Updated(query));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Пример #2
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            PerioperativeService service = new PerioperativeService();

            try
            {
                service.PhysicalDelRecord(key.ToString());
                return(Ok(true));
            }
            catch (Exception)
            {
                return(Ok(false));
            }
        }
Пример #3
0
        public IHttpActionResult Get(ODataQueryOptions <PerioperativeEntity> odataQueryOptions)
        {
            Expression <Func <PerioperativeEntity, bool> > myfilter = null;

            if (odataQueryOptions.Filter != null)
            {
                myfilter = odataQueryOptions.Filter.ToExpression <PerioperativeEntity>();
            }
            try
            {
                PerioperativeService service = new PerioperativeService();
                var expression = LinqExtensions.True <PerioperativeEntity>();
                if (myfilter != null)
                {
                    expression = expression.And(myfilter);
                }
                var query = service.IQueryRecord(expression).ToList();
                return(Ok(query.AsQueryable()));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Пример #4
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="model"></param>
        public void Post(PerioperativeEntity model)
        {
            PerioperativeService service = new PerioperativeService();

            service.SaveEntity(model.ID, model);
        }
Пример #5
0
        /// <summary>
        /// 更新数据,幂等
        /// </summary>
        /// <param name="key"></param>
        /// <param name="model"></param>
        public void Put([FromODataUri] string key, PerioperativeEntity model)
        {
            PerioperativeService service = new PerioperativeService();

            service.UpdateEntity(model);
        }