public async Task <IActionResult> UpdateManufacturer(int id, [FromForm] ManufacturerToUpdate manufacturer)
        {
            var toUpdateManufacturer = await _context.Manufacturer.FirstOrDefaultAsync(m => m.Manufacturerid == id);

            if (toUpdateManufacturer == null)
            {
                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(manufacturer, toUpdateManufacturer);
            return(Ok(await _context.SaveChangesAsync()));
        }
Example #2
0
        public async Task <IActionResult> UpdateRetailStore(int id, [FromForm] RetailstoreToUpdate retailstore)
        {
            var toUpdateRetailstore = await _context.Retailstore.FirstOrDefaultAsync(r => r.Storeid == id);

            if (toUpdateRetailstore == null)
            {
                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(retailstore, toUpdateRetailstore);
            return(Ok(await _context.SaveChangesAsync()));
        }
        public async Task <IActionResult> UpdateBikeparts(int serialnumber, int componentid, [FromForm] BikepartsToUpdate bikeparts)
        {
            var toUpdateBikeParts = await _context.Bikeparts.FirstOrDefaultAsync(b => b.Serialnumber == serialnumber && b.Componentid == componentid);

            if (toUpdateBikeParts == null)
            {
                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(bikeparts, toUpdateBikeParts);
            return(Ok(await _context.SaveChangesAsync()));
        }
Example #4
0
        public async Task <IActionResult> UpdateCity(int id, [FromForm] CityToUpdate city)
        {
            var toUpdateCity = await _context.City.FirstOrDefaultAsync(c => c.Cityid == id);

            if (toUpdateCity == null)
            {
                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(city, toUpdateCity);
            return(Ok(await _context.SaveChangesAsync()));
        }
Example #5
0
        public async Task <IActionResult> PutPaint(int id, [FromBody] PaintToUpdate paint)
        {
            var toUpdatePaint = await _context.Paint.FirstOrDefaultAsync(b => b.Paintid == id);

            if (toUpdatePaint == null)
            {
                return(NoContent());
            }

            _mapper.Map(paint, toUpdatePaint);
            await _context.SaveChangesAsync();

            return(Ok(paint));
        }
Example #6
0
        public async Task <IActionResult> UpdateBicycle(int id, [FromBody] BicycleToUpdate bicycle)
        {
            var toUpdateBicycle = await _context.Bicycle.FirstOrDefaultAsync(b => b.Serialnumber == id);

            if (toUpdateBicycle == null)
            {
                await TimeStampError();

                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(bicycle, toUpdateBicycle);
            await TimeStampTransaction();

            return(Ok(await _context.SaveChangesAsync()));
        }
Example #7
0
        public async Task <IActionResult> UpdateComponent(int id, [FromBody] ComponetToUpdate component)
        {
            var toUpdateComponent = await _context.Component.FirstOrDefaultAsync(c => c.Componentid == id);

            if (toUpdateComponent == null)
            {
                await TimeStampError();

                return(NoContent());
            }
            // map our form data to our updated model
            _mapper.Map(component, toUpdateComponent);
            await TimeStampTransaction();

            return(Ok(await _context.SaveChangesAsync()));
        }
Example #8
0
        public async Task <IActionResult> CreateCustomer([FromBody] CustomerToCreate customer)
        {
            // Missing parameters
            // More info in response
            if (!ModelState.IsValid)
            {
                await TimeStampError();

                return(BadRequest());
            }

            // map the customer model
            // USES: automapper instead of handtyped
            var newCustomer = _mapper.Map <Customer>(customer);

            _context.Add(newCustomer);

            await _context.SaveChangesAsync();

            await TimeStampTransaction();

            return(Ok(newCustomer));
        }