Example #1
0
        public async Task <IActionResult> EditFuelType(int id, [FromForm] FuelTypeDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Something want wrong while updating fuel type"));
            }

            var fuelTypeToEdit = await _fuelTypeService.GetFuelTypeByIdAsync(id);

            if (fuelTypeToEdit == null)
            {
                return(BadRequest("Fuel Type not found"));
            }

            fuelTypeToEdit.Name = model.Name;

            await _fuelTypeService.UpdateFuelTypeAsync(fuelTypeToEdit);

            await _genericRepository.SaveChangesAsync();

            return(Ok(new
            {
                status = 200,
                message = "Brand edited successfully"
            }));
        }
Example #2
0
        public async Task <IActionResult> GetFuelTypeById(int id)
        {
            var model = new FuelTypeDto();
            var fuel  = await _fuelTypeService.GetFuelTypeByIdAsync(id);

            if (fuel == null)
            {
                return(BadRequest("Location not found"));
            }

            model.Id   = fuel.Id;
            model.Name = fuel.Name;

            return(Ok(model));
        }