コード例 #1
0
        public ActionResult Update(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return(this.Json(new { Message = "Validation error" }));
            }

            var repository = new MongoDbBitcoinAccountRepository();

            ObjectId id;

            if (!ObjectId.TryParse(model.Id, out id))
            {
                throw new ArgumentException();
            }

            var account = repository.GetById(id);

            repository.Save(account);

            return(Json(new
            {
                Message = "OK",
                Data = new BitcoinAccountModel
                {
                    Id = account.Id.ToString(),
                    Address = account.Address,
                    Name = account.Name
                }
            }));
        }
コード例 #2
0
        public ActionResult Update(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return this.Json(new { Message = "Validation error" });
            }

            var repository = new MongoDbBitcoinAccountRepository();

            ObjectId id;
            if (!ObjectId.TryParse(model.Id, out id))
            {
                throw new ArgumentException();
            }

            var account = repository.GetById(id);

            repository.Save(account);

            return Json(new
            {
                Message = "OK",
                Data = new BitcoinAccountModel
                {
                    Id = account.Id.ToString(),
                    Address = account.Address,
                    Name = account.Name
                }
            });
        }
コード例 #3
0
        public ActionResult Add(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return this.Json(new {Message = "Validation error"});
            }
            var account = new BitcoinAccount(User.Identity.GetUserId(), model.Name, model.Address);

            var repository = new MongoDbBitcoinAccountRepository();
            repository.Add(account);

            return Json(new {Message = "OK", Data = new BitcoinAccountModel
            {
                Id = account.Id.ToString(),
                Address = account.Address,
                Name = account.Name
            } });
        }
コード例 #4
0
        public ActionResult Add(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return(this.Json(new { Message = "Validation error" }));
            }
            var account = new BitcoinAccount(User.Identity.GetUserId(), model.Name, model.Address);

            var repository = new MongoDbBitcoinAccountRepository();

            repository.Add(account);

            return(Json(new { Message = "OK", Data = new BitcoinAccountModel
                              {
                                  Id = account.Id.ToString(),
                                  Address = account.Address,
                                  Name = account.Name
                              } }));
        }
コード例 #5
0
        public ActionResult Delete(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return this.Json(new {Message = "Validation error"});
            }

            var account = new BitcoinAccount(User.Identity.GetUserId(), model.Name, model.Address);

            var repository = new MongoDbBitcoinAccountRepository();
            ObjectId id;
            if (!ObjectId.TryParse(model.Id, out id))
            {
                throw new ArgumentException();
            }
            
            repository.Remove(id);

            return Json(new {Message = "OK", Data = account });
        }
コード例 #6
0
        public ActionResult Delete(BitcoinAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                this.Response.StatusCode = 401;
                return(this.Json(new { Message = "Validation error" }));
            }

            var account = new BitcoinAccount(User.Identity.GetUserId(), model.Name, model.Address);

            var      repository = new MongoDbBitcoinAccountRepository();
            ObjectId id;

            if (!ObjectId.TryParse(model.Id, out id))
            {
                throw new ArgumentException();
            }

            repository.Remove(id);

            return(Json(new { Message = "OK", Data = account }));
        }