Example #1
0
        internal void WriteSubDivisionInfo(LomsContext db, SubDivision sub, out Zone zone, out Region region)
        {
            zone = null;
            region = null;

            if (sub.StateId != null)
            {
                State state = db.States.Include("Country").FirstOrDefault(s => s.Id == sub.StateId);
                if (state != null)
                    Write(", {0}", state.Acronym);

                if (state.Country != null)
                    WriteLine(", {0}", state.Country.Name);
            }

            if (sub.DivisionId != null)
            {
                Division division = db.Divisions.Include("Zone").Include("Zone.Region").FirstOrDefault(d => d.Id == sub.DivisionId);
                if (division != null && division.Zone != null)
                {
                    zone = division.Zone;
                    if (division.Zone.Region != null)
                    {
                        region = division.Zone.Region;
                        Write("{0} / ", region != null ? division.Zone.Region.Name : "");
                    }
                    Write("{0} / ", division.Zone != null ? division.Zone.Name : "");
                }
                WriteLine("{0} / {1}", division != null ? division.Name : "", sub.Name);

                //if (division != null && division.zoneId != ObjectId.Null)
                //{
                //    zone = AppDal.Zone.Get(transaction, division.zoneId);
                //    if (zone != null && zone.regionId != ObjectId.Null)
                //    {
                //        region = AppDal.Region.Get(transaction, zone.regionId);
                //        Write("{0} / ", region != null ? region.name : "");
                //    }
                //    Write("{0} / ", zone != null ? zone.name : "");
                //}
                //WriteLine("{0} / {1}", division != null ? division.name : "", sub.name);
            }
            else
                WriteLine(" /  /  / {0}", sub.Name);
        }
Example #2
0
        public bool Contains(Region region, Zone zone, Division division, SubDivision subDivision)
        {
            if (!RegionId.HasValue && !ZoneId.HasValue && !DivisionId.HasValue && !SubDivisionId.HasValue) //all regions
                return true;

            if (RegionId.HasValue && region != null && RegionId == region.Id)  //by region
                return true;

            if (ZoneId.HasValue && zone != null && ZoneId == zone.Id)  //by zone
                return true;

            if (DivisionId.HasValue && division != null && DivisionId == division.Id)  //by division
                return true;

            if (SubDivisionId.HasValue && subDivision != null && SubDivisionId == subDivision.Id)  //by division
                return true;

            return false;
        }
Example #3
0
        private static List<AdminFee> GetAdminFees(LomsContext db, Booking booking, Zone zoneFrom, Region regionFrom, Zone zoneTo, Region regionTo)
        {
            var date = (from d in db.AdminFeeDates
                        where d.CountryId == booking.City.CountryId && d.StartDate <= booking.PickUpTime
                        orderby d.StartDate descending
                        select d)
                        .Take(1).FirstOrDefault();

            if (date == null)
                return null;

            var fees = new List<AdminFee>();

            var regionFees = from f in db.RegionAdminFeeValues
                             where
                             f.DateId == date.Id
                             &&
                             (
                                 f.FromId == regionFrom.Id && f.ToId == regionTo.Id ||
                                 f.FromId.HasValue && f.ToId == regionTo.Id ||
                                 f.FromId == regionFrom.Id && !f.ToId.HasValue
                             )
                             select f;
            regionFees.ForEach(rf => fees.Add(new AdminFee(rf.Margin, rf.Fee)));


            var zoneFees = from f in db.ZoneAdminFeeValues
                           where
                           f.DateId == date.Id
                           &&
                           (
                               f.FromId == regionFrom.Id && f.ToId == regionTo.Id ||
                               f.FromId == null && f.ToId == regionTo.Id ||
                               f.FromId == regionFrom.Id && f.ToId == null
                             )
                           select f;
            zoneFees.ForEach(zf => fees.Add(new AdminFee(zf.Margin, zf.Fee)));

            return fees;
        }
Example #4
0
     private void FixupRegion(Region previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.EventAreas.Contains(this))
         {
             previousValue.EventAreas.Remove(this);
         }
 
         if (Region != null)
         {
             if (!Region.EventAreas.Contains(this))
             {
                 Region.EventAreas.Add(this);
             }
 
             RegionId = Region.Id;
         }
         else if (!skipKeys)
         {
             RegionId = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Region")
                 && (ChangeTracker.OriginalValues["Region"] == Region))
             {
                 ChangeTracker.OriginalValues.Remove("Region");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Region", previousValue);
             }
             if (Region != null && !Region.ChangeTracker.ChangeTrackingEnabled)
             {
                 Region.StartTracking();
             }
         }
     }
Example #5
0
     public bool Equals(Region other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.Id == 0 && Id == 0)
 			return false;
 		else
 			return other.Id == Id;
     }
Example #6
0
     private void FixupRegion1(Region previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.RegionAdminFeeValues1.Contains(this))
         {
             previousValue.RegionAdminFeeValues1.Remove(this);
         }
 
         if (Region1 != null)
         {
             if (!Region1.RegionAdminFeeValues1.Contains(this))
             {
                 Region1.RegionAdminFeeValues1.Add(this);
             }
 
             ToId = Region1.Id;
         }
         else if (!skipKeys)
         {
             ToId = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Region1")
                 && (ChangeTracker.OriginalValues["Region1"] == Region1))
             {
                 ChangeTracker.OriginalValues.Remove("Region1");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Region1", previousValue);
             }
             if (Region1 != null && !Region1.ChangeTracker.ChangeTrackingEnabled)
             {
                 Region1.StartTracking();
             }
         }
     }
Example #7
0
     private void FixupRegion(Region previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (Region != null)
         {
             RegionId = Region.Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Region")
                 && (ChangeTracker.OriginalValues["Region"] == Region))
             {
                 ChangeTracker.OriginalValues.Remove("Region");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Region", previousValue);
             }
             if (Region != null && !Region.ChangeTracker.ChangeTrackingEnabled)
             {
                 Region.StartTracking();
             }
         }
     }