コード例 #1
0
        public async Task Add_ReturnsNewItem()
        {
            var newItem = await _valueService.Add(new ValueModel { Name = "new value" });

            Assert.IsNotNull(newItem);
            Assert.IsTrue((newItem as IValueModel).Name == "new value");
            Assert.IsTrue((newItem as IValueModel).Id > 2);
        }
コード例 #2
0
        public IActionResult Post([FromBody] NewValueViewModel newValue)
        {
            Value value = _valueService.Add(new Value()
            {
                Content = newValue.Content
            });

            value.AddSelfLink(_uriHelper, "get", "Values");
            value.AddLink(_uriHelper, "delete", "Values", "del", new { id = value.Id });
            return(new CreatedAtActionResult("Get", "Values", new { id = value.Id }, value));
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] NewValuesViewModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var createdObject = await _valueService.Add(new models.ValueModel {
                Name = value.Name
            });

            return(Created($"api/Values/", value.Name));
        }
コード例 #4
0
 public ActionResult <ValueEntity> AddValue([FromBody] ValueEntity value)
 {
     try
     {
         return(CreatedAtAction("GET", _services.Add(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(new ErrorMessage()
         {
             message = e.Message, code = ErrorCodes.NotCreatedModel
         }));
     }
 }
コード例 #5
0
 public Value Post([FromBody] Value value)
 {
     value = _valueService.Add(value);
     return(value);
 }