public IHttpActionResult Post(InstrumentCreate instrument) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateInstrumentService(); if (!service.CreateInstrument(instrument)) { return(InternalServerError()); } return(Ok(instrument)); }
public bool CreateInstrument(InstrumentCreate model) { var entity = new Instrument() { Description = model.Description, Name = model.Name, ModelName = model.ModelName, Brand = model.Brand, ExpLvl = model.ExpLvl, Quantity = model.Quantity, Price = model.Price, OwnerId = _userId, ClassificationId = model.ClassificationId, }; using (var ctx = new ApplicationDbContext()) { ctx.Instruments.Add(entity); return(ctx.SaveChanges() == 1); } }