Exemple #1
0
 public Neighborhood DeleteNeighborhood(int id)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         Neighborhood found = context.Find <Neighborhood>(id);
         context.Remove(found);
         context.SaveChanges();
         return(found);
     }
 }
Exemple #2
0
 public Neighborhood AddNeighborhood(Neighborhood entity)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(entity.City).State = EntityState.Unchanged;
         context.Add(entity);
         context.SaveChanges();
         return(entity);
     }
 }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
 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);
     }
 }