Exemplo n.º 1
0
        public void TestGetUser2()
        {
            var users = SampleModel.GetUsers();

            User user;
            var  tryGetUserResult = SampleModel.TryGetUser(users.Count == 0 ? 1 : users.Max(x => x.Id) + 1, out user);

            Assert.True(!tryGetUserResult);
            Assert.True(user == null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// コンストラクター。
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            foreach (var user in SampleModel.GetUsers())
            {
                Users.Add(user);
            }

            UserListView.ItemsSource = Users;
        }
Exemplo n.º 3
0
        public void TestGetUser1()
        {
            var users = SampleModel.GetUsers();

            Assert.False(users.Count == 0, "テスト前にデータ登録が必要。");

            User user;
            var  tryGetUserResult = SampleModel.TryGetUser(users[0].Id, out user);

            Assert.True(tryGetUserResult);
            Assert.True(user != null);
            Assert.Equal(user.Id, users[0].Id);
            Assert.Equal(user.Name, users[0].Name);
        }
Exemplo n.º 4
0
        public ActionResult Api(ApiReq req)
        {
            var res = new ApiRes();

            switch (req.cmd)
            {
            case "LIST":
                var u = new SampleModel();
                res.users = u.GetUsers();
                break;

            case "SELECT":
            {
                user users = db.users.Find(req.id);
                if (users == null)
                {
                    res.res = "NG";
                }
                else
                {
                    res.user = users;
                }
                break;
            }

            case "UPDATE":
                if (!ModelState.IsValid)
                {
                    res.res = "NG";
                }
                else
                {
                    db.Entry(req.user).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        res.res = "NG";
                        res.msg = e.ToString();
                    }
                }
                break;

            case "INSERT":
                if (ModelState.IsValid)
                {
                    db.users.Add(req.user);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        res.res = "NG";
                        res.msg = e.ToString();
                    }
                }
                break;

            default:
                res.res = "NG";
                res.msg = "Bad Request";
                break;
            }
            return(Json(res));
        }