public Neighborhood DeleteNeighborhood(int id) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood found = context.Find <Neighborhood>(id); context.Remove(found); context.SaveChanges(); return(found); } }
public Neighborhood AddNeighborhood(Neighborhood entity) { using (PropertyHubContext context = new PropertyHubContext()) { context.Entry(entity.City).State = EntityState.Unchanged; context.Add(entity); context.SaveChanges(); return(entity); } }
public Neighborhood GetNeighborhood(int id) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood area = (from a in context.Neighborhoods .Include(a => a.City.Province.Country) where a.Id == id select a).FirstOrDefault(); return(area); } }
public Neighborhood UpdateNeighborhood(int id, Neighborhood area) { using (PropertyHubContext context = new PropertyHubContext()) { Neighborhood found = context.Find <Neighborhood>(id); if (!string.IsNullOrWhiteSpace(area.Name)) { found.Name = area.Name; } if (area.City?.Id != 0) { found.City = area.City; context.Entry(found.City).State = EntityState.Unchanged; } found.Image = area.Image; context.SaveChanges(); return(found); } }