public IActionResult Post([FromBody] TurbineTypeViewModel model) { if (model == null) { return(new StatusCodeResult(500)); } var turbineType = DbContext.TurbineTypes.Where(t => t.Id == model.Id).FirstOrDefault(); if (turbineType == null) { return(NotFound(new { Error = String.Format("TurbineType ID {0} has not been found", model.Id) })); } turbineType.Model = model.Model; turbineType.Capacity = model.Capacity; DbContext.SaveChanges(); return(new JsonResult( turbineType.Adapt <TurbineTypeViewModel>(), JsonSettings)); }
public IActionResult Put([FromBody] TurbineTypeViewModel model) { if (model == null) { return(new StatusCodeResult(500)); } var turbineType = model.Adapt <TurbineType>(); DbContext.TurbineTypes.Add(turbineType); DbContext.SaveChanges(); // return the newly-created Quiz to the client. return(new JsonResult(turbineType.Adapt <QuizViewModel>(), JsonSettings)); }