public static RealEstate GetById(int realtyId)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         return(context.RealEstate.FirstOrDefault(x => x.Id == realtyId));
     }
 }
        public static IEnumerable <RealEstate> GetList(RealEstateFilter filter = null)
        {
            using (AgencyDbEntities context = new AgencyDbEntities())
            {
                if (filter == null)
                {
                    return(context.RealEstate.ToList());
                }

                IQueryable <RealEstate> realtyQuery = context.RealEstate;

                if (filter.RealEstateType.HasValue)
                {
                    realtyQuery = realtyQuery.Where(x => x.Discriminator == filter.RealEstateType.ToString());
                }

                if (!string.IsNullOrWhiteSpace(filter.Address))
                {
                    return(realtyQuery.ToArray().Where(x =>
                                                       LevenshteinHelper.LevenshteinDistance($"{x.City} {x.Street} {x.HouseNumber} {x.FlatNumber}", filter.Address)
                                                       <= LevenshteinHelper.ApplicationLevenshteinDistance ||
                                                       LevenshteinHelper.LevenshteinDistance(x.City + " " + x.Street, filter.Address)
                                                       <= LevenshteinHelper.ApplicationLevenshteinDistance ||
                                                       LevenshteinHelper.LevenshteinDistance(x.HouseNumber + " " + x.FlatNumber, filter.Address)
                                                       <= LevenshteinHelper.ApplicationLevenshteinMinDistance));
                }

                return(realtyQuery.ToList());
            }
        }
示例#3
0
 public static Client GetById(int clientId)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         return(context.Client.FirstOrDefault(x => x.Id == clientId));
     }
 }
 public static void Create(RealEstate realEstate)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.RealEstate.Add(realEstate);
         context.SaveChanges();
     }
 }
 public static void Delete(RealEstate realEstate)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.Entry(realEstate).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
示例#6
0
 public static void Create(Client client)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.Client.Add(client);
         context.SaveChanges();
     }
 }
示例#7
0
 public static void Delete(Client client)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.Entry(client).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public static void Update(RealEstate realEstate)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.RealEstate.Attach(realEstate);
         context.Entry(realEstate).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#9
0
 public static void Update(Client client)
 {
     using (AgencyDbEntities context = new AgencyDbEntities())
     {
         context.Client.Attach(client);
         context.Entry(client).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#10
0
        public static IEnumerable <Realtor> GetList(string name = null)
        {
            using (AgencyDbEntities context = new AgencyDbEntities())
            {
                if (!string.IsNullOrEmpty(name))
                {
                    return(context.Realtor.ToArray()
                           .Where(x => LevenshteinHelper.LevenshteinDistance
                                      (x.LastName + " " + x.FirstName + " " + x.Patronymic, name)
                                  <= LevenshteinHelper.ApplicationLevenshteinDistance ||
                                  (x.LastName + " " + x.FirstName + " " + x.Patronymic).Contains(name))
                           .ToList());
                }

                return(context.Realtor.ToList());
            }
        }