public void Delete(int Id) { Vehicle v = null; ProjetasContext _contextInMemory = new ProjetasContext(this.GetDBOptions()); using (_contextInMemory) { v = new Vehicle { Id = 2, Brand = "Nissan", Model = "Skyline GTR R34", Color = "Silver", Year = 1999, Description = "Make movies better", ItsNew = false }; _contextInMemory.Vehicle.Attach(v); _contextInMemory.Vehicle.Remove(v); _contextInMemory.Entry(v).State = EntityState.Deleted; _contextInMemory.SaveChanges(); } Assert.IsNotNull(v); }
public void Update(Vehicle v) { ProjetasContext _contextInMemory = new ProjetasContext(this.GetDBOptions()); v = new Vehicle { Id = 1, Brand = "Dodge", Model = "Charger R/T", Color = "Black", Year = 1970, Description = "I can fly!", ItsNew = false }; using (_contextInMemory) { _contextInMemory.Vehicle.Add(v); Vehicle _dbEntity = _contextInMemory.Vehicle.Find(1); _contextInMemory.Entry(_dbEntity).CurrentValues.SetValues(v); _contextInMemory.SaveChanges(); Assert.IsTrue(v.Id != -1); } }
public static IList <Vehicle> FindByColor(string color) { IList <Vehicle> _vehicle = null; using (var context = new ProjetasContext()) { _vehicle = context.Vehicle.Where(c => c.Color.Contains(color)).ToList(); } return(_vehicle); }
public static IList <Vehicle> FindByBrand(string brand) { IList <Vehicle> _vehicle = null; using (var context = new ProjetasContext()) { _vehicle = context.Vehicle.Where(c => c.Brand.Contains(brand)).ToList(); } return(_vehicle); }
public static Vehicle FindById(long id) { Vehicle _vehicle = null; using (var context = new ProjetasContext()) { _vehicle = context.Vehicle.Where(c => c.Id == id).FirstOrDefault(); } return(_vehicle); }
public static List <Vehicle> FindAll() { IEnumerable <Vehicle> _vehicle = null; using (var context = new ProjetasContext()) { _vehicle = context.Vehicle; return(_vehicle != null?_vehicle.ToList() : null); } }
public static int Update(Vehicle _vehicle) { using (var context = new ProjetasContext()) { Vehicle _dbEntity = context.Vehicle.Find(_vehicle.Id); context.Entry(_dbEntity).CurrentValues.SetValues(_vehicle); context.SaveChanges(); return(_vehicle.Id); } }
public void AddVehicle(Vehicle vehicle) { ProjetasContext _contextInMemory = new ProjetasContext(this.GetDBOptions()); Vehicle _v = new Vehicle(); _v.Id = vehicle.Id + 1; _v.Brand = vehicle.Brand; _v.Model = vehicle.Model; _v.Color = vehicle.Color; _v.Year = vehicle.Year; _v.Description = vehicle.Description; _v.ItsNew = vehicle.ItsNew; _contextInMemory.AddRange(_v); _contextInMemory.SaveChanges(); }
public void GetAllVehicle() { IEnumerable <Vehicle> _vehicles = null; ProjetasContext _contextInMemory = new ProjetasContext(this.GetDBOptions()); using (_contextInMemory) { int id = 0; _contextInMemory.Vehicle.Add(new Vehicle { Id = id++, Brand = "Toyota", Model = "Supra MK IV", Color = "Orange", Year = 1994, Description = "I can do 400m in less than 10 seconds", ItsNew = false }); _contextInMemory.Vehicle.Add(new Vehicle { Id = id++, Brand = "Nissan", Model = "Skyline GTR R34", Color = "Silver", Year = 1999, Description = "Make movies better", ItsNew = false }); _contextInMemory.Vehicle.Add(new Vehicle { Id = id++, Brand = "Dodge", Model = "Charger R/T", Color = "Black", Year = 1970, Description = "I can fly!", ItsNew = false }); _contextInMemory.SaveChanges(); _vehicles = _contextInMemory.Vehicle.ToList(); } Assert.IsNotNull(_vehicles); Assert.IsTrue(_vehicles.ToList().Count > 0); }
public static int Add(Vehicle _vehicle) { try { using (var context = new ProjetasContext()) { context.Vehicle.Add(_vehicle); context.SaveChanges(); return(_vehicle.Id); } } catch (Exception dbEx) { string message = string.Format("{0}", dbEx.Message); return(0); } }
public static void Delete(IList <Vehicle> _vehicle) { try { using (var context = new ProjetasContext()) { foreach (Vehicle c in _vehicle) { context.Vehicle.Attach(c); context.Vehicle.Remove(c); context.Entry(c).State = EntityState.Deleted; } context.SaveChanges(); } } catch (Exception dbEx) { string message = string.Format("{0}", dbEx.Message); } }
public void GetVehicleById(int id) { Vehicle _vehicle = null; ProjetasContext _contextInMemory = new ProjetasContext(this.GetDBOptions()); using (_contextInMemory) { _contextInMemory.Vehicle.Add(new Vehicle { Id = id, Brand = "Toyota", Model = "Supra MK IV", Color = "Orange", Year = 1994, Description = "I can do 400m in less than 10 seconds", ItsNew = false }); _vehicle = _contextInMemory.Vehicle.Where(c => c.Id == id).FirstOrDefault(); Assert.IsTrue(_vehicle != null); } }