public JsonResult SelectOilBundle(string brand, string level, string viscosity)
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.SelectOilBundle(brand, level, viscosity);

            return(Json(new { Status = result.Item1, Data = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 获取机油产品名
        /// </summary>
        /// <param name="brand"></param>
        /// <param name="level"></param>
        /// <param name="viscosity"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public JsonResult SelectOilDisplayName(string brand, string level, string viscosity, string unit)
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.SelectOilDisplayNameByProperty(brand, level, viscosity, unit);

            return(Json(new { Status = result != null, Data = result }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 获取机油粘度
        /// </summary>
        /// <returns></returns>
        public JsonResult SelectOilviscosity()
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.SelectOilviscosity();

            return(Json(new { Status = result.Item1, Data = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult EditYearCardInfo(string promotionCode, string cardItemStr, string PID)
        {
            var  manager = new BaoYangManager();
            bool result  = manager.EditYearCardInfo(promotionCode, cardItemStr, PID, User.Identity.Name);

            return(Json(new { Status = result }));
        }
        /// <summary>
        /// 获取机油品牌
        /// </summary>
        /// <returns></returns>
        public JsonResult GetAllFuelBrand()
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.SelectAllFuelBrand();

            return(Json(new { Status = result.Item1, Data = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 获取年卡保养项目
        /// </summary>
        /// <param name="yearCardId"></param>
        /// <returns></returns>
        public JsonResult GetYearCardDetails(int yearCardId)
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.SelectBaoYangYearCardDetails(yearCardId);

            return(Json(new { Status = result.Item1, Data = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 验证年卡PID
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public JsonResult IsExistBaoYangYearCardPid(string pid)
        {
            BaoYangManager manager = new BaoYangManager();
            var            result  = manager.IsBaoYangYearCardPidValidate(pid);

            return(Json(new { Status = result.Item1, Msg = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult DeleteBaoYangYearCard(int pkid)
        {
            BaoYangManager manager = new BaoYangManager();
            var            user    = User.Identity.Name;
            var            result  = manager.DeleteBaoYangYearCard(pkid, user);

            return(Json(new { Status = result }));
        }
        public JsonResult GetBaoYangYearCardInfo(int pageIndex, string pid, string category, string fuelBrand, string productId)
        {
            BaoYangManager manager    = new BaoYangManager();
            var            pageSize   = 15;
            var            result     = manager.SelectAllBaoYangYearCard(pageIndex, pageSize, pid, category, fuelBrand, productId);
            var            totalCount = manager.SelectBaoYangYearCardCount(pid, category, fuelBrand, productId);

            return(Json(new { Status = result.Item1, Data = result.Item2.OrderByDescending(p => p.Pkid), TotalCount = totalCount }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult BaoYangYearCardConfig()
        {
            BaoYangManager        manager = new BaoYangManager();
            List <string>         oil     = manager.SelectAllFuelBrand().Item2;
            List <YearCardConfig> config  = manager.SelectYearCardConfig();
            var model = new Tuple <List <YearCardConfig>, List <string> > (config, oil);

            return(View(model));
        }
        public JsonResult CreateYearCardPromotionCode(long orderId = 0)
        {
            if (orderId <= 0)
            {
                return(Json(new { Status = false, Msg = "OrderId是必须的" }, JsonRequestBehavior.AllowGet));
            }
            var manager = new BaoYangManager();
            var result  = manager.CreateYearCardPromotionCode(orderId);

            return(Json(result));
        }
        public JsonResult GetYearCardInfo(long orderId = 0)
        {
            if (orderId <= 0)
            {
                return(Json(new { Status = false, Msg = "OrderId是必须的" }, JsonRequestBehavior.AllowGet));
            }
            var manager = new BaoYangManager();
            var result  = manager.SelectBaoYangYearCardInfo(orderId);

            return(Json(new { Status = result.Item1, Data = result.Item2 }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddBaoYangYearCardInfo(string yearCard, string shop, string detail, string promotion)
        {
            var            mainYearCard           = JsonConvert.DeserializeObject <YearCardParameter>(yearCard);
            var            yearCardShop           = JsonConvert.DeserializeObject <List <BaoYangYearCardShop> >(shop);
            var            yearCardDetail         = JsonConvert.DeserializeObject <List <BaoYangYearCardDetail> >(detail);
            var            promotionPercentage    = JsonConvert.DeserializeObject <List <BaoYangYearCardPromotion> >(promotion);
            bool           IsAddShopSucceed       = false;
            bool           IsAddCardDetailSucceed = false;
            bool           IsAddPromotionSuccess  = false;
            BaoYangManager manager = new BaoYangManager();
            var            user    = User.Identity.Name;

            if (mainYearCard.Pkid == 0) //新增一张年卡
            {
                var addYearCard = manager.AddBaoYangYearCard(mainYearCard, user);
                if (addYearCard.Item1)
                {
                    var newYearCardId = addYearCard.Item2;
                    foreach (var itemShop in yearCardShop)
                    {
                        itemShop.YearCardId = newYearCardId;
                    }
                    foreach (var itemDeatil in yearCardDetail)
                    {
                        itemDeatil.YearCardId = newYearCardId;
                    }
                    foreach (var itemPromotion in promotionPercentage)
                    {
                        itemPromotion.YearCardId = newYearCardId;
                    }
                    IsAddShopSucceed       = yearCardShop.Count <= 0 || manager.AddBaoYangYearCardShop(yearCardShop, user);
                    IsAddCardDetailSucceed = yearCardDetail.Count <= 0 || manager.AddBaoYangYearCardDetail(yearCardDetail, user);
                    IsAddPromotionSuccess  = promotionPercentage.Count <= 0 || manager.AddYearCardPromotionPercentage(promotionPercentage, user);
                    if (IsAddShopSucceed && IsAddCardDetailSucceed && IsAddPromotionSuccess)
                    {
                        return(Json(new { Status = true, Data = newYearCardId }));
                    }
                }
            }
            else //更新原有年卡数据
            {
                var IsUpdateYearCardSucceed = manager.UpdateBaoYangYearCardInfo(mainYearCard, user);
                IsAddShopSucceed       = yearCardShop.Count <= 0 || manager.AddBaoYangYearCardShop(yearCardShop, user);
                IsAddCardDetailSucceed = yearCardDetail.Count <= 0 || manager.AddBaoYangYearCardDetail(yearCardDetail, user);
                IsAddPromotionSuccess  = promotionPercentage.Count <= 0 || manager.AddYearCardPromotionPercentage(promotionPercentage, user);
                if (IsUpdateYearCardSucceed && IsAddShopSucceed && IsAddCardDetailSucceed && IsAddPromotionSuccess)
                {
                    return(Json(new { Status = true, Data = mainYearCard.Pkid }));
                }
            }
            return(Json(new { Status = false }));
        }
        public JsonResult AddOrUpdateYearCardConfig(string configObj)
        {
            var            user               = User.Identity.Name;
            var            configParameter    = JsonConvert.DeserializeObject <List <YearCardConfig> >(configObj);
            BaoYangManager manager            = new BaoYangManager();
            var            isConfigSuccess    = manager.AddOrUpdateYearCardConfig(configParameter, user);
            var            isRecommendSuccess = manager.AddOrUpdateYearCardRecommendConfig(configParameter, user);

            if (isConfigSuccess && isRecommendSuccess)
            {
                return(Json(new { Status = true }));
            }
            return(Json(new { Status = false }));
        }
        public JsonResult UpdateBaoYangYearcardConfig()
        {
            var            msg     = "更新线上缓存成功!";
            BaoYangManager manager = new BaoYangManager();
            bool           result;

            try
            {
                result = manager.UpdateBaoYangYearcardConfig();
            }
            catch (Exception ex) {
                result = false;
                msg    = "更新线上缓存失败, 错误信息:" + ex.Message;
            }
            return(Json(new { Status = result, Msg = msg }));
        }
        /// <summary>
        /// 验证产品PID
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public JsonResult CheckProductName(string pid)
        {
            string         result  = string.Empty;
            BaoYangManager manager = new BaoYangManager();

            if (!string.IsNullOrWhiteSpace(pid))
            {
                result = manager.SelectProductNameByPid(pid);
            }
            else
            {
                return(Json(new { status = "fail" }, JsonRequestBehavior.AllowGet));
            }
            return(!string.IsNullOrWhiteSpace(result) ? Json(new { status = "success", Data = result }, JsonRequestBehavior.AllowGet)
                                : Json(new { status = "fail" }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult YearCardDetail(int YearCardId = 0)
        {
            ViewBag.Pkid = 0;
            if (YearCardId == 0)
            {
                return(View());
            }
            BaoYangManager manager = new BaoYangManager();
            var            data    = manager.SelectYearCardInfoByPkid(YearCardId);

            if (data != null && data.Count > 0)
            {
                ViewBag.Pkid = YearCardId;
                return(View(data));
            }
            return(View());
        }