Exemple #1
0
        public ActionResult CouponGenerator(ViewSingleDeal CreateCoupon)
        {
            if (Session[KeyList.SessionKeys.UserID] == null)
            {
                return(RedirectToAction("Index", "Register_Login"));
            }

            //    walleservice = new UserWalletServices(new DealsDB());
            walleservice = new UserWalletServices(new DealsDB());
            Wallet AddTrans = walleservice.GetCreditByUserID(Convert.ToInt32(Session[DealsNZ.Helpers.KeyList.SessionKeys.UserID].ToString()));

            if (CreateCoupon.CouponPrice > AddTrans.WalletCredit)
            {
                walleservice.Dispose();
            }
            else
            {
                AddTrans.UserId           = Convert.ToInt32(Session[DealsNZ.Helpers.KeyList.SessionKeys.UserID].ToString());
                AddTrans.WalletCredit     = Convert.ToDecimal(Convert.ToDecimal(AddTrans.WalletCredit) - Convert.ToDecimal(CreateCoupon.CouponPrice));
                AddTrans.WalletCreditDate = System.DateTime.Now;

                Wallet DealUserWallet = walleservice.GetCreditByDealUserID(CreateCoupon.DealId);
                DealUserWallet.WalletCredit = Convert.ToDecimal(Convert.ToDecimal(DealUserWallet.WalletCredit) + Convert.ToDecimal(CreateCoupon.CouponPrice));

                if (walleservice.WalletUpdate(AddTrans) == true && walleservice.WalletUpdate(DealUserWallet) == true)
                {
                    Coupon InsertCoupon = new Coupon()
                    {
                        CouponUniqueText = CreateCoupon.DealId.ToString() + GenerateCode(),
                        CouponValidTill  = CreateCoupon.ValidTill,
                        CouponQty        = CreateCoupon.CouponQty,
                        CouponPrice      = CreateCoupon.CouponPrice,
                        AddedOn          = System.DateTime.Now.Date,
                        DealId           = CreateCoupon.DealId,
                        UserId           = Convert.ToInt32(Session[KeyList.SessionKeys.UserID]),
                        ReedemNo         = 0
                    };
                    couponservice = new CouponService(new DealsDB());
                    couponservice.Insert(InsertCoupon);
                    couponservice.Dispose();
                    Session[KeyList.SessionKeys.WalletCredit] = walleservice.ShowWalletAmount(Convert.ToInt32(Session[DealsNZ.Helpers.KeyList.SessionKeys.UserID].ToString()));
                    walleservice.Dispose();
                    string       CouponBody         = createEmailBody(CreateCoupon.StoreName, CreateCoupon.Address, CreateCoupon.Title, CreateCoupon.Price.ToString(), CreateCoupon.StrikePrice.ToString(), CreateCoupon.Discount.ToString(), InsertCoupon.CouponQty.ToString(), InsertCoupon.CouponValidTill.ToString(), InsertCoupon.CouponUniqueText);
                    string       Title              = "Coupon For " + CreateCoupon.Title;
                    IUserProfile UserProfileService = new UserProfileServices(new DealsDB());
                    if (UserProfileService.UserMail(CouponBody, Title, Session[KeyList.SessionKeys.UserEmail].ToString()) == true)
                    {
                        dealServices = new DealServices(new DealsDB());
                        ViewSingleDeal SingleDeal = dealServices.GetSingleDeal(CreateCoupon.DealId);
                        dealServices.Dispose();
                        ViewBag.Message = "Check Your Mail To Get Coupon";
                        return(View("Index", SingleDeal));
                    }
                }
                else
                {
                    walleservice.Dispose();
                }
            }

            return(View());
        }