Example #1
0
        /// <summary>
        /// 检查是否在配送范围
        /// </summary>
        /// <param name="model"></param>
        /// <param name="db"></param>
        /// <param name="shop"></param>
        public static void CheckIsInScope(this MemberAddress model, ShopDbContext db, Shop shop)
        {
            ShopTakeOutInfo toInfo = db.Query <ShopTakeOutInfo>()
                                     .Where(m => !m.IsDel)
                                     .Where(m => m.ShopId == shop.Id)
                                     .FirstOrDefault();

            if (toInfo == null)
            {
                throw new Exception("外卖基础设置不存在");
            }
            model.CheckIsInScope(shop, toInfo);
        }
Example #2
0
        /// <summary>
        /// 检查是否在配送范围
        /// </summary>
        /// <param name="model"></param>
        /// <param name="shopId"></param>
        /// <param name="IsConglomeration">是否为拼团添加地址</param>
        void CheckIsInScope(MemberAddress model, int shopId, bool IsConglomeration)
        {
            string address = model.GetAddress();

            if (model.GetCoordinates())
            {
                if (!IsConglomeration)
                {
                    model.CheckIsInScope(db, shopId);
                }
            }
            else
            {
                throw new Exception("当前地址无法获取相应的坐标");
            }
        }
Example #3
0
        /// <summary>
        /// 设置当前地址为使用中的地址
        /// </summary>
        /// <param name="memberAddress"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static bool SetAddressIsUsed(this MemberAddress memberAddress, ShopDbContext db, int shopId, int memberId, bool IsConglomeration)
        {
            if (IsConglomeration)
            {
                memberAddress.CheckIsInScope(db, shopId);
            }

            var list = db.Query <MemberAddress>()
                       .Where(m => m.MemberId == memberId)
                       .Where(m => !m.IsDel)
                       .ToList();

            foreach (var item in list)
            {
                item.IsUsed = false;
            }
            memberAddress.IsUsed = true;
            db.SaveChanges();

            return(true);
        }
Example #4
0
        /// <summary>
        /// 检查是否在配送范围
        /// </summary>
        /// <param name="model"></param>
        /// <param name="db"></param>
        /// <param name="shopId"></param>
        public static void CheckIsInScope(this MemberAddress model, ShopDbContext db, int shopId)
        {
            var shop = db.GetSingle <Shop>(shopId);

            model.CheckIsInScope(db, shop);
        }