Esempio n. 1
0
        public static Neighborhood Find(ISession session, string name, string city, string state, string country)
        {
            if (string.IsNullOrEmpty(country))
            {
                throw new ManagedCountry.InvalidCountryException();
            }

            if (string.IsNullOrEmpty(city))
            {
                throw new ManagedCity.InvalidCityException();
            }

            City c = ManagedCity.Find(session, city, state, country);

            Neighborhood neighborhood = (Neighborhood)session.CreateCriteria(typeof(Neighborhood))
                                        .Add(Expression.Eq("Name", name))
                                        .Add(Expression.Eq("City.Id", c.Id))
                                        .UniqueResult();

            if (neighborhood == null)
            {
                throw new InvalidNeighborhoodException();
            }

            return(neighborhood);
        }
Esempio n. 2
0
        public override Neighborhood GetInstance(ISession session, ManagedSecurityContext sec)
        {
            Neighborhood instance = base.GetInstance(session, sec);

            instance.Name = this.Name;
            if (!string.IsNullOrEmpty(City))
            {
                instance.City = ManagedCity.Find(session, City, State, Country);
            }
            return(instance);
        }
Esempio n. 3
0
 public static Neighborhood FindOrCreate(ISession session, string name, string city, string state, string country)
 {
     try
     {
         return(Find(session, name, city, state, country));
     }
     catch (InvalidNeighborhoodException)
     {
         Neighborhood neighborhood = new Neighborhood();
         neighborhood.City = ManagedCity.Find(session, city, state, country);
         neighborhood.Name = name;
         session.Save(neighborhood);
         return(neighborhood);
     }
 }