Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostProduct(InputPackage input)
        {
            var package = input.ToModel();

            await _context.Packages.AddAsync(package);

            await _context.SaveChangesAsync();

            return(Ok(_packageHandler.OutputFor(package)));
        }