public static void CalcDistance(this CouponTypeModel coupon, LocationModel location)
 {
     if (location == null) location = new LocationModel(32.067141, 34.804314); // default location Teatron Givataim
     IServicesLayer m_serviceLayer = new ServiceLayerImpl();
     if (coupon.Location != null && location != null)
     {
         coupon.Distance = m_serviceLayer.CalculateDistanceInKm(coupon.Location, location);
     }
     else
     {
         coupon.Distance = 6000;
     }
 }
Exemple #2
0
        public void TestSortCouponsListByDistance_ShouldCalculateDistanceAttributeForeachCouponTypeModel_AndSortListByDistanceValue()
        {
            CouponType tempCoupon1 = new CouponType()
            {
                Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "11111" },
                LocationsList = new List<Location>() { new Location(0.1, 0.1) }
            };
            CouponType tempCoupon2 = new CouponType()
            {
                Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "22222" },
                LocationsList = new List<Location>() { new Location(0.5, 0.5) }
            };
            CouponType tempCoupon3 = new CouponType()
            {
                Description = "אכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "33333" },
                LocationsList = new List<Location>() { new Location(0.3, 0.3) }
            };
            CouponType tempCoupon4 = new CouponType()
            {
                Description = "1+1 על כל בירה מהחבית במסעדת Red Burger Bar, כל יום עד שעה 19:00.",
                RestaurantsIDs = new List<string>() { "44444" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(1, 1) }
            };
            CouponType tempCoupon5 = new CouponType()
            {
                Description = "1+1 על סטייק אנטריקוט, בהזמנה מנה עיקרית ושתייה, במסעדת Red Burger Bar.",
                RestaurantsIDs = new List<string>() { "55555" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(32.067141, 34.804314) }
            };
            CouponType tempCoupon6 = new CouponType()
            {
                Description = "מנת ילד חינם בהזמנה מנה עיקרית למבוגר במסעדת Palamida, ביום שישי 12:00-16:00",
                RestaurantsIDs = new List<string>() { "66666" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(0.6, 0.6) }
            };
            CouponType tempCoupon7 = new CouponType()
            {
                Description = "ארוחה זוגית ב- 200 שח הארוחה כוללת: - 2 כוסות יין הבית - 2 מרק + לחם הבית - מיקס פירות ים, במסעדת Palamida.",
                RestaurantsIDs = new List<string>() { "77777" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(0.2, 0.2) }
            };

            List<CouponType> couponList = new List<CouponType>(){ tempCoupon1, tempCoupon2, tempCoupon3, tempCoupon4, tempCoupon5, tempCoupon6, tempCoupon7 };
            List<CouponTypeModel> couponModelList = couponList.ToCouponTypeModelList();
            //Act
            LocationModel location = new LocationModel(0, 0);
            foreach (var item in couponModelList)
            {
                item.CalcDistance(location);
            }
            var list = couponModelList.OrderBy(c=> c.Distance).ToList();

            //Assert
            Assert.IsNotNull(couponModelList);
            Assert.AreEqual(list[0].RestaurantID, "11111");
            Assert.AreEqual(list[1].RestaurantID, "77777");
            Assert.AreEqual(list[2].RestaurantID, "33333");
            Assert.AreEqual(list[3].RestaurantID, "22222");
            Assert.AreEqual(list[4].RestaurantID, "66666");
            Assert.AreEqual(list[5].RestaurantID, "44444");
            Assert.AreEqual(list[6].RestaurantID, "55555");
        }
        public static List<UserMedalModel> ToUserMedalModel(this List<UserMedal> Medals, LocationModel location = null)
        {
            try
            {
                if (Medals == null || Medals.Count == 0) return new List<UserMedalModel>();
                List<UserMedalModel> returnValue = new List<UserMedalModel>();
                foreach (var item in Medals)
                {
                    UserMedalModel medal = item.ToUserMedalModel();
                    if (medal != null)
                    {
                        if (medal.Coupon != null) medal.Coupon.CalcDistance(location);
                        returnValue.Add(medal);
                    }
                }

                log.InfoFormat("[ToUserMedalModel] List<UserMedalModel>={0}.", Medals.ToString());
                return returnValue.OrderBy(c => c.CreatedAt).ToList();
            }
            catch (Exception e)
            {
                log.ErrorFormat("[ToUserMedalModel] List<UserMedalModel>,  Exception={0}.", e.ToString());
                return null;
            }
        }
 public double CalculateDistanceInRad(LocationModel location1, LocationModel location2)
 {
     double e = (3.1415926538 * location1.Latitude / 180);
     double f = (3.1415926538 * location1.Longitude / 180);
     double g = (3.1415926538 * location2.Latitude / 180);
     double h = (3.1415926538 * location2.Longitude / 180);
     double i = (Math.Cos(e) * Math.Cos(g) * Math.Cos(f) * Math.Cos(h) + Math.Cos(e) * Math.Sin(f) * Math.Cos(g) * Math.Sin(h) + Math.Sin(e) * Math.Sin(g));
     double j = (Math.Acos(i));
     return j;
 }
 public double CalculateDistanceInRad(LocationModel location1, LocationModel location2)
 {
     throw new NotImplementedException();
 }