public IBaseCommandResult Handle(CreateEquipmentCommand command) { command.Validate(); if (command.Invalid) { return(new BaseCommandResult(false, "Need to fix the errors on Equipment", command.Notifications)); } var user = _userRepository.GetById(command.UserId); if (user == null) { return(new BaseCommandResult(false, "User not found", null)); } //logic here: if manufacturer and/or model don't exists, i will create it and attach to equipment var manufacturer = _manufacturerRepository.GetByDescription(command.Manufacturer); if (manufacturer == null) { manufacturer = new Manufacturer(command.Manufacturer); _manufacturerRepository.Create(manufacturer); } var deviceModel = _deviceModelRepository.GetByDescriptionAndManufacturer(command.Model, manufacturer); if (deviceModel == null) { deviceModel = new DeviceModel(command.Model, manufacturer); _deviceModelRepository.Create(deviceModel); } var equipment = new Equipment(command.AndroidId, command.Imei1, command.Imei2, command.PhoneNumber, command.MacAddress, command.ApiLevel, command.ApiLevelDesc, command.SerialNumber, command.SystemName, command.SystemVersion, deviceModel, user); _repository.Create(equipment); return(new BaseCommandResult(true, "Equipment Saved with Success!", new { Id = equipment.Id.ToString() })); }