public void CanInsertVehicleMake() { var repo = new VehicleMakeRepository(); MakesItem newMake = new MakesItem() { VehicleMakeName = "Subaru", UserId = "00000000-0000-0000-0000-000000000000" }; repo.Insert(newMake); var allMakes = repo.GetVehicleMakes().ToList(); Assert.AreEqual(6, allMakes.Count()); Assert.AreEqual("Subaru", allMakes[5].VehicleMakeName); }
public void Insert(MakesItem make) { using (var cn = new SqlConnection()) { cn.ConnectionString = Settings.GetConnectionString(); var parameters = new DynamicParameters(); parameters.Add("@VehicleMakeId", dbType: DbType.Int32, direction: ParameterDirection.Output); parameters.Add("@VehicleMakeName", make.VehicleMakeName); parameters.Add("@UserId", make.UserId); cn.Execute("InsertVehicleMake", parameters, commandType: CommandType.StoredProcedure); make.VehicleMakeId = parameters.Get <int>("@VehicleMakeId"); } }
public void Insert(MakesItem make) { var lastId = _vehicleMakes.MaxBy(x => x.VehicleMakeId).FirstOrDefault(); int newId = lastId.VehicleMakeId + 1; make.VehicleMakeId = newId; _makesItems.Add(make); VehicleMake newMake = new VehicleMake() { VehicleMakeId = make.VehicleMakeId, VehicleMakeName = make.VehicleMakeName, UserId = make.UserId, CreatedDate = make.CreatedDate }; _vehicleMakes.Add(newMake); }