public void OnNavigatedTo(NavigationContext navigationContext)
        {
            var couponHistory = CouponsService.Instance.CouponHistory;

            foreach (var coupon in couponHistory)
            {
                CouponHistory.Add(coupon);
            }
        }
        public IEnumerable <CouponHistory> GetRecentValidHistory()
        {
            var isValid = GetIsCouponHistoryValid();

            if (isValid)
            {
                return(CouponHistory.Where(c => c.Date > DateTime.UtcNow.AddDays(30)));
            }

            return(Enumerable.Empty <CouponHistory>());
        }
Esempio n. 3
0
        public ActionResult Edit(Coupon coupon, HttpPostedFileBase file, int id = 0)
        {
            int            paramId = 0;
            EasyPayContext context = new EasyPayContext();

            logger.Info("Edit HttpPost Method Start" + " at " + DateTime.UtcNow);
            Merchant merchant = new Merchant {
                MerchantId = id
            };

            context.Merchants.Attach(merchant);

            Category category = new Category {
                CategoryId = coupon.Category_CategoryId
            };

            context.Categories.Attach(category);
            Coupon coup = context.Coupons.Where(c => c.CouponId == coupon.CouponId).FirstOrDefault();

            if (coupon.TotalCoupons != coup.TotalCoupons)
            {
                CouponHistory couponHistory = new CouponHistory()
                {
                    AdditionalFees = coupon.AdditionalFees,

                    Category          = category,
                    CouponCode        = coupon.CouponCode,
                    CouponImagepath   = coupon.CouponImagepath,
                    CouponId          = coupon.CouponId,
                    CouponsAddedDate  = DateTime.Today,
                    CouponTitle       = coupon.CouponTitle,
                    CouponValue       = coupon.CouponValue,
                    Description       = coupon.Description,
                    IsValid           = coupon.IsValid,
                    Merchant          = merchant,
                    Published         = coupon.Published,
                    Store             = coupon.Store,
                    Terms             = coupon.Terms,
                    TotalCouponsAdded = coupon.TotalCoupons,
                    Type          = coupon.Type,
                    Url           = coupon.Url,
                    ValidInCities = coupon.ValidInCities,
                    ValidityEnd   = coupon.ValidityEnd,
                    ValidityStart = coupon.ValidityStart
                };
                context.CouponHistories.Add(couponHistory);
            }
            coupon.TotalCoupons    += coup.TotalCoupons;
            coupon.AvailableCoupons = coupon.TotalCoupons - coup.CouponsUsed;
            string path = utils.SaveFile(file);

            if (ModelState.IsValid)
            {
                if (path != null)
                {
                    coupon.CouponImagepath = path;
                }
                context.Entry(coupon).State = EntityState.Modified;

                context.SaveChanges();
                paramId = (id == 0) ? 0 : coupon.MerchantId;
                return(RedirectToAction("Index", new { id = paramId }));
            }
            ViewBag.MerchantId = new SelectList(context.Merchants, "MerchantId", "MerchantName", coupon.MerchantId);
            logger.Info("Edit HttpPost Method End" + " at " + DateTime.UtcNow);
            return(View(coupon));
        }
Esempio n. 4
0
        public ActionResult CopyCoupon(Coupon thisCoupon, int id = 0)
        {
            int            paramId = 0;
            EasyPayContext context = new EasyPayContext();
            Coupon         coupon  = context.Coupons.Find(id);

            Merchant merchant = new Merchant {
                MerchantId = coupon.MerchantId
            };

            context.Merchants.Attach(merchant);

            Category category = new Category {
                CategoryId = coupon.Category_CategoryId
            };

            context.Categories.Attach(category);
            Coupon newCoupon = new Coupon()
            {
                AdditionalFees   = coupon.AdditionalFees,
                AvailableCoupons = thisCoupon.TotalCoupons,
                Category         = category,
                CouponCode       = coupon.CouponCode,
                CouponImagepath  = coupon.CouponImagepath,
                CouponsUsed      = coupon.CouponsUsed,
                CouponTitle      = coupon.CouponTitle,
                CouponValue      = coupon.CouponValue,
                Description      = coupon.Description,
                IsValid          = coupon.IsValid,
                Merchant         = merchant,
                MerchantId       = merchant.MerchantId,
                Published        = coupon.Published,
                Store            = coupon.Store,
                Terms            = coupon.Terms,
                TotalCoupons     = thisCoupon.TotalCoupons,
                Type             = coupon.Type,
                Url           = coupon.Url,
                ValidInCities = coupon.ValidInCities,
                ValidityEnd   = coupon.ValidityEnd,
                ValidityStart = coupon.ValidityStart
            };
            CouponHistory couponHistory = new CouponHistory()
            {
                AdditionalFees = coupon.AdditionalFees,

                Category          = category,
                CouponCode        = coupon.CouponCode,
                CouponImagepath   = coupon.CouponImagepath,
                CouponId          = newCoupon.CouponId,
                CouponsAddedDate  = DateTime.Today,
                CouponTitle       = coupon.CouponTitle,
                CouponValue       = coupon.CouponValue,
                Description       = coupon.Description,
                IsValid           = coupon.IsValid,
                Merchant          = merchant,
                Published         = coupon.Published,
                Store             = coupon.Store,
                Terms             = coupon.Terms,
                TotalCouponsAdded = newCoupon.TotalCoupons,
                Type          = coupon.Type,
                Url           = coupon.Url,
                ValidInCities = coupon.ValidInCities,
                ValidityEnd   = coupon.ValidityEnd,
                ValidityStart = coupon.ValidityStart
            };

            context.CouponHistories.Add(couponHistory);
            context.Coupons.Add(newCoupon);
            context.SaveChanges();
            paramId = (id == 0) ? 0 : newCoupon.MerchantId;
            return(RedirectToAction("Index", new { id = paramId }));
        }
Esempio n. 5
0
        public ActionResult Create(Coupon coupon, HttpPostedFileBase file, int id = 0)
        {
            EasyPayContext context = new EasyPayContext();
            int            mId     = 0;
            int            paramId = 0;

            logger.Info("Create Method Start" + " at " + DateTime.UtcNow);

            string path = utils.SaveFile(file);

            if (coupon != null)
            {
                if (path != null)
                {
                    coupon.CouponImagepath = path;
                }

                var a = ViewBag.Merchant;
                mId = (id != 0) ? id : coupon.MerchantId;

                Merchant merchant = new Merchant {
                    MerchantId = mId
                };
                context.Merchants.Attach(merchant);

                Category category = new Category {
                    CategoryId = coupon.Category_CategoryId
                };
                context.Categories.Attach(category);
                Coupon newCoupon = new Coupon()
                {
                    AdditionalFees   = coupon.AdditionalFees,
                    AvailableCoupons = coupon.TotalCoupons,
                    Category         = category,
                    CouponCode       = coupon.CouponCode,
                    CouponImagepath  = path,
                    CouponsUsed      = coupon.CouponsUsed,
                    CouponTitle      = coupon.CouponTitle,
                    CouponValue      = coupon.CouponValue,
                    Description      = coupon.Description,
                    IsValid          = coupon.IsValid,
                    Merchant         = merchant,
                    MerchantId       = merchant.MerchantId,
                    Published        = coupon.Published,
                    Store            = coupon.Store,
                    Terms            = coupon.Terms,
                    TotalCoupons     = coupon.TotalCoupons,
                    Type             = coupon.Type,
                    Url           = coupon.Url,
                    ValidInCities = coupon.ValidInCities,
                    ValidityEnd   = coupon.ValidityEnd,
                    ValidityStart = coupon.ValidityStart
                };
                CouponHistory couponHistory = new CouponHistory()
                {
                    AdditionalFees = coupon.AdditionalFees,

                    Category          = category,
                    CouponCode        = coupon.CouponCode,
                    CouponImagepath   = coupon.CouponImagepath,
                    CouponId          = newCoupon.CouponId,
                    CouponsAddedDate  = DateTime.Today,
                    CouponTitle       = coupon.CouponTitle,
                    CouponValue       = coupon.CouponValue,
                    Description       = coupon.Description,
                    IsValid           = coupon.IsValid,
                    Merchant          = merchant,
                    Published         = coupon.Published,
                    Store             = coupon.Store,
                    Terms             = coupon.Terms,
                    TotalCouponsAdded = newCoupon.TotalCoupons,
                    Type          = coupon.Type,
                    Url           = coupon.Url,
                    ValidInCities = coupon.ValidInCities,
                    ValidityEnd   = coupon.ValidityEnd,
                    ValidityStart = coupon.ValidityStart
                };
                context.CouponHistories.Add(couponHistory);
                context.Coupons.Add(newCoupon);
                context.SaveChanges();
                //State state = new State();
                //var thisMerchant = context.Merchants.Where(m => m.MerchantId == id).FirstOrDefault();
                //var thisUserState = context.UserProfiles.Where(u => u.UserProfileId == thisMerchant.UserProfileId).Select(y => y.StateID).FirstOrDefault();
                //using (EasyPayContext context = new EasyPayContext())
                //{
                //    coupon.MerchantId = id;
                //    context.Coupons.Add(coupon);
                //    context.SaveChanges();
                //}

                //coupon.Merchant.State_StateID = thisUserState;
                //coupon.Merchant.CategoryId = thisMerchant.CategoryId;
                //coupon.Merchant.UserProfileId = thisMerchant.UserProfileId;
                //coupon.MerchantId = id;
                //coupon.Category_CategoryId = 3;
                paramId = (id == 0) ? 0 : newCoupon.MerchantId;

                return(RedirectToAction("Index", new { id = paramId }));
            }

            ViewBag.MerchantId = new SelectList(context.Merchants, "MerchantId", "MerchantName", coupon.MerchantId);
            logger.Info("Create Method End" + " at " + DateTime.UtcNow);
            return(View(coupon));
        }