public async Task <int> AddNew([FromBody] NewItemDto newItem)
        {
            int newItemId = -1;

            //A bit of duplicate looking code, but we want to make sure the type matches
            // a case before we do any work, and we want to make sure work has been done
            // before we save any changes.
            switch (newItem.ItemType)
            {
            case "make":
            {
                VehicleMake makeToAdd = new VehicleMake {
                    VehicleMakeName = newItem.ItemValue
                };
                await _vehicleMakeRepository.AddAsync(makeToAdd);

                await _vehicleMakeRepository.SaveChangesAsync();

                newItemId = makeToAdd.VehicleMakeId;
                break;
            }

            case "model":
            {
                VehicleModel modelToAdd = new VehicleModel {
                    VehicleModelName = newItem.ItemValue, VehicleMakeId = newItem.ItemParentId
                };
                await _vehicleModelRepository.AddAsync(modelToAdd);

                await _vehicleMakeRepository.SaveChangesAsync();

                newItemId = modelToAdd.VehicleModelId;
                break;
            }
            }
            //we are only expecting one change
            return(newItemId);
        }
Пример #2
0
        public async Task <IVehicleMake> CreateMake(IVehicleMake make)
        {
            make = await Repository.AddAsync(Mapper.Map <IVehicleMake>(make));

            return(make);
        }