Example #1
0
        public bool UpdateMaterial(int id, MaterialFormModel data)
        {
            Material materialFromDB = _context.Material.Find(id);

            if (materialFromDB == null)
            {
                return(false);
            }
            data.MaterialId = id;

            _context.Entry(materialFromDB).CurrentValues.SetValues(data);
            _context.SaveChanges();
            return(true);
        }
Example #2
0
        public MaterialModel CreateMaterial(MaterialFormModel data)
        {
            Material newMaterial = new Material();

            _context.Material.Add(newMaterial);
            _context.Entry(newMaterial).CurrentValues.SetValues(data);
            _context.SaveChanges();
            return(new MaterialModel
            {
                MaterialId = newMaterial.MaterialId,
                SupplierId = newMaterial.SupplierId,
                Name = newMaterial.Name,
                MinStock = newMaterial.MinStock,
                PackagingSize = newMaterial.PackagingSize,
                Unit = newMaterial.Unit,
                Price = newMaterial.Price,
                Supplier = newMaterial.Supplier
            });
        }
Example #3
0
 public bool UpdateMaterial(int id, [FromBody] MaterialFormModel data)
 {
     return(this._context.UpdateMaterial(id, data));
 }
Example #4
0
 public MaterialModel CreateMaterial([FromBody] MaterialFormModel data)
 {
     return(this._context.CreateMaterial(data));
 }