Exemplo n.º 1
0
        public async Task <ApiResult <string> > Update(int id, [FromBody] TestEditWebModel model)
        {
            var r = new ApiResult <string>();

            if (!id.Equals(model.Id))
            {
                r.status = 400;
                r.msg    = "传入Id与实体Id不一致";
                return(r);
            }
            var isExist = await _testServices.IsExist(id);

            if (!isExist)
            {
                r.status = 404;
                r.msg    = "未匹配到数据";
                return(r);
            }
            try
            {
                r.status = await _testServices.UpdateAsync(t => t.Id == id, t => new Test()
                {
                    Name = model.Name, MDate = DateTime.Now.ToLocalTime()
                }) == 0 ? 200 : 400;

                r.msg = r.status == 200 ? "更新成功" : "更新失败";
            }
            catch (Exception ex)
            {
                r.status = 500;
                r.msg    = ex.Message;
            }
            return(r);
        }