コード例 #1
0
        public IHttpActionResult Post(InstrumentCreate instrument)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateInstrumentService();

            if (!service.CreateInstrument(instrument))
            {
                return(InternalServerError());
            }

            return(Ok(instrument));
        }
コード例 #2
0
        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);
            }
        }