internal int ApplyPromoCode(PromoCodeReq objReq)
 {
     try
     {
         using (var db = new WizzDataContext())
         {
             tblPromoCode promoCodeData = new tblPromoCode();
             long fkUserId = Convert.ToInt64(objReq.userId);
             promoCodeData = db.tblPromoCodes.Where(p => p.promoCode == objReq.promocode && p.isDelete == false).FirstOrDefault();
             if (promoCodeData == null)
                 return 0;
             else if (DateTime.UtcNow.IsBetween(promoCodeData.validFrom.Value, promoCodeData.validTo.Value) || promoCodeData.isActive == false)
                 return 3;
             else if (db.tblPromoHistories.Any(d => d.fkUserId == fkUserId && d.fkPromoCodeId == promoCodeData.pkPromoCodeId))
                 return 2;
             else if (db.tblPromoHistories.Count(x => x.fkPromoCodeId == promoCodeData.pkPromoCodeId) > promoCodeData.usageCount)
                 return 3;
             else
             {
                 tblPromoHistory objHistory = new tblPromoHistory();
                 objHistory.fkPromoCodeId = promoCodeData.pkPromoCodeId;
                 objHistory.createdDate = DateTime.UtcNow;
                 objHistory.fkUserId = Convert.ToInt64(objReq.userId);
                 db.tblPromoHistories.InsertOnSubmit(objHistory);
                 //  tblUser userDetails = new tblUser();
                 var userDetails = db.tblUsers.Where(u => u.pkUserId == fkUserId).FirstOrDefault();
                 userDetails.credits += Convert.ToInt32(promoCodeData.discountPercentage);
                 db.SubmitChanges();
                 return 1;
             }
         }
     }
     catch (Exception e)
     {
         return 0;
     }
 }
 /// <summary>
 /// There are no comments for tblPromoCode in the schema.
 /// </summary>
 public void AddTotblPromoCode(tblPromoCode tblPromoCode)
 {
     base.AddObject("tblPromoCode", tblPromoCode);
 }
 /// <summary>
 /// Create a new tblPromoCode object.
 /// </summary>
 /// <param name="promoCode">Initial value of PromoCode.</param>
 /// <param name="percentageDiscount">Initial value of PercentageDiscount.</param>
 /// <param name="promoCodeUsed">Initial value of PromoCodeUsed.</param>
 /// <param name="createDate">Initial value of CreateDate.</param>
 public static tblPromoCode CreatetblPromoCode(string promoCode, byte percentageDiscount, bool promoCodeUsed, global::System.DateTime createDate)
 {
     tblPromoCode tblPromoCode = new tblPromoCode();
     tblPromoCode.PromoCode = promoCode;
     tblPromoCode.PercentageDiscount = percentageDiscount;
     tblPromoCode.PromoCodeUsed = promoCodeUsed;
     tblPromoCode.CreateDate = createDate;
     return tblPromoCode;
 }