コード例 #1
0
 public ActionResult AddMobile([FromBody] Mobile mobile)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var item = _Mobile.AddMobile(mobile);
             return(CreatedAtAction("Get", new { id = mobile.Id }, item));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
コード例 #2
0
        public IActionResult AddMobile(MobileViewModel request)
        {
            if (ModelState.IsValid)
            {
                Phone mobile = new Phone()
                {
                    Name         = request.Name,
                    Manufacturer = _manufacturerService.GetManufacturerById(request.ManufacturerId),
                    Price        = request.Price
                };


                _mobileService.AddMobile(mobile);

                return(Ok());
            }

            return(BadRequest());
        }