public async Task <IActionResult> UpdateProduct(int id, InputPackage input) { var currentPackage = await _context.Packages.FindAsync(id); if (currentPackage == null) { return(NotFound()); } var newPackage = input.ToModel(); currentPackage.Name = newPackage.Name; currentPackage.Description = newPackage.Description; currentPackage.BaseValue = newPackage.BaseValue; currentPackage.PricePerPhoto = newPackage.PricePerPhoto; currentPackage.ImageQuantity = newPackage.ImageQuantity; currentPackage.QuantityMultiplier = newPackage.QuantityMultiplier; currentPackage.QuantityMultiplier = newPackage.QuantityMultiplier; currentPackage.MaxIterations = newPackage.MaxIterations; currentPackage.Available = newPackage.Available; await _context.SaveChangesAsync(); return(Ok(_packageHandler.OutputFor(currentPackage))); }
public async Task <IActionResult> PostProduct(InputPackage input) { var package = input.ToModel(); await _context.Packages.AddAsync(package); await _context.SaveChangesAsync(); return(Ok(_packageHandler.OutputFor(package))); }