示例#1
0
        public IHttpActionResult Put(LiquorEdit liquor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = new LiquorService();

            if (!service.UpdateLiquor(liquor))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
示例#2
0
        public bool UpdateLiquor(LiquorEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx.Liquors
                    .Single(e => e.Id == model.Id);

                entity.Name           = model.Name;
                entity.Category       = model.Category;
                entity.PercentAlcohol = model.PercentAlcohol;
                entity.Origin         = model.Origin;

                return(ctx.SaveChanges() == 1);
            }
        }