Exemple #1
0
        public async Task <IActionResult> Put(int id, [FromBody] Product value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var model = Context.Product.Find(id);

            if (model == null)
            {
                return(NotFound());
            }
            model.ListPrice     = value.ListPrice;
            model.ModifiedDate  = DateTime.Now;
            model.Color         = value.Color;
            model.ProductModel  = value.ProductModel;
            model.ProductNumber = value.ProductNumber;

            model.Size         = value.Size;
            model.StandardCost = value.StandardCost;
            model.Weight       = value.Weight;

            Context.Product.Update(model);

            await Context.SaveChangesAsync();

            return(Ok());
        }
Exemple #2
0
        public IActionResult Post([FromBody] Product value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var model = Context.Product.Find(value.ProductId);

            if (model == null)
            {
                return(NotFound());
            }
            model.ListPrice     = value.ListPrice;
            model.ModifiedDate  = DateTime.Now;
            model.Color         = value.Color;
            model.ProductModel  = value.ProductModel;
            model.ProductNumber = value.ProductNumber;

            model.Size         = value.Size;
            model.StandardCost = value.StandardCost;
            model.Weight       = value.Weight;

            Context.Product.Add(model);

            Context.SaveChanges();

            return(Ok());
        }