Ejemplo n.º 1
0
        public IHttpActionResult Patch([FromODataUri] string key, Delta <PainScoreEntity> patch)
        {
            PainScoreService service = new PainScoreService();
            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);
                patch.Patch(query);
                service.UpdateEntity(query);
                return(Updated(query));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            PainScoreService service = new PainScoreService();

            try
            {
                service.PhysicalDelRecord(key);
                return(Ok(true));
            }
            catch (Exception)
            {
                return(Ok(false));
            }
        }
        public IHttpActionResult RecordPagination(Pagination pagination)
        {
            PainScoreService service = new PainScoreService();

            try
            {
                var query         = service.RecordPagination(pagination);
                var packageEntity = query.PackageEntityPaginations(pagination);
                return(Json(packageEntity));
            }
            catch (Exception)
            {
                PackageResultEntity <object> packageResultEntity = new PackageResultEntity <object>()
                {
                    list = null,
                    msg  = "failed"
                };
                return(Json(packageResultEntity));
            }
        }
        public IHttpActionResult RecordQuery(string key)
        {
            PainScoreService service = new PainScoreService();

            try
            {
                var query         = service.GetEntity(key);
                var packageEntity = query.PackageResult();
                return(Json(packageEntity));
            }
            catch (Exception)
            {
                PackageResultEntity <object> packageResultEntity = new PackageResultEntity <object>()
                {
                    list = null,
                    msg  = "failed"
                };
                return(Json(packageResultEntity));
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult Get(ODataQueryOptions <PainScoreEntity> odataQueryOptions)
        {
            Expression <Func <PainScoreEntity, bool> > myfilter = null;

            if (odataQueryOptions.Filter != null)
            {
                myfilter = odataQueryOptions.Filter.ToExpression <PainScoreEntity>();
            }
            try
            {
                PainScoreService service = new PainScoreService();
                var expression           = LinqExtensions.True <PainScoreEntity>();
                if (myfilter != null)
                {
                    expression = expression.And(myfilter);
                }
                var query = service.IQueryRecord(expression).ToList();
                return(Ok(query.AsQueryable()));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="model"></param>
        public void Post(PainScoreEntity model)
        {
            PainScoreService service = new PainScoreService();

            service.SaveEntity(model.ID, model);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新数据,幂等
        /// </summary>
        /// <param name="key"></param>
        /// <param name="model"></param>
        public void Put([FromODataUri] string key, PainScoreEntity model)
        {
            PainScoreService service = new PainScoreService();

            service.UpdateEntity(model);
        }