// POST api/users //新建 public Object Post(UserApiModel obj) { string msg; try { User obj4save = obj.ToDto(); BaseActionResult result = BusinessService.CreateUser(obj4save); return new { IsSuccess = result.IsSuccess, Message = result.Message }; } catch (Exception e) { msg = string.Format(XiaoluResources.MSG_CREATE_FAIL, obj.Name) + string.Format(XiaoluResources.STR_FAIL_RESAON, ExceptionHelper.GetInnerExceptionInfo(e)); return new { IsSuccess = false, Message = msg }; } }
// PUT api/users/5 //修改 public Object Put(string id, UserApiModel obj) { string msg; try { User obj4save = obj.ToDto(); User objinDb = BusinessService.GetUserById(id); if (objinDb == null) { msg = string.Format(XiaoluResources.MSG_OBJECT_NOT_FOUND_WITH_ID, id); return new { IsSuccess = false, Message = msg }; } objinDb.Name = obj4save.Name; objinDb.Description = obj4save.Description; objinDb.Gender = obj4save.Gender; objinDb.Birthday = obj4save.Birthday; objinDb.Level = obj4save.Level; objinDb.Status = obj4save.Status; objinDb.Mobile = obj4save.Mobile; objinDb.WeixinId = obj4save.WeixinId; BaseActionResult result = BusinessService.UpdateUser(objinDb); return new { IsSuccess = result.IsSuccess, Message = result.Message }; } catch (Exception e) { msg = string.Format(XiaoluResources.MSG_CREATE_FAIL, obj.Name) + string.Format(XiaoluResources.STR_FAIL_RESAON, ExceptionHelper.GetInnerExceptionInfo(e)); return new { IsSuccess = false, Message = msg }; } }