public async Task Delete(LocationModel entity) { using (var db = new WincChallengeDbEntities()) { var l = await db.Locations.Where(x => x.Id == entity.Id).SingleOrDefaultAsync(); if (l != null) { db.Locations.Remove(l); await db.SaveChangesAsync(); } } }
public async Task Create(LocationModel entity) { using (var db = new WincChallengeDbEntities()) { var l = new Location { Country = entity.Country, Name = entity.Name, State = entity.State, Zipcode = entity.Zipcode }; db.Locations.Add(l); await db.SaveChangesAsync(); entity.Id = l.Id; } }
public async Task <LocationModel> GetById(int id) { using (var db = new WincChallengeDbEntities()) { var l = await db.Locations.Where(x => x.Id == id).SingleOrDefaultAsync(); if (l == null) { return(null); } return(new LocationModel { Id = l.Id, Country = l.Country, Name = l.Name, State = l.State, Zipcode = l.Zipcode }); } }