public ActionResult CouponConsume(CouponConsumeModel couponData) { ViewBag.SubmitButtonTest = "Consume"; if (ModelState.IsValid) { //tCoupon coupon = _coupoRepository.FindByCustomNo(couponData.CouponNo); //if (coupon == null) { // ModelState.AddModelError("Coupon", "Coupon Not Found!"); // return View(couponData); //} //int UserID = (int)MembershipHelper.GetCurrenUser().ProviderUserKey; //if (coupon.IDPartner != UserID) { // ModelState.AddModelError("Coupon", "User is Wrong For this Coupon!"); // return View(couponData); //} //if (coupon.Code != couponData.CouponCode) { // ModelState.AddModelError("Coupon", "Coupon Code Not Valid!"); // return View(couponData); //} tCoupon coupon = ValidateCoupon(couponData); if (!ModelState.IsValid) { return(View(couponData)); } coupon.ConsumeStatus = (int)Enums.enmCouponConsumeStatus.Consumed; coupon.tOrders.FirstOrDefault().RefundStatus = (int)Enums.enmRefundStatus.OrderSuccessful; _coupoRepository.InsertOrUpdate(coupon); _coupoRepository.Save(); ViewBag.CurrentMessage = "Coupon Consumed Succesfully!"; } return(View(couponData)); }
public JsonResult CreateAjax(tCoupon user, int Count) { if (ModelState.IsValid) { user.DateAdded = DateTime.Now; if (user.DateBegin < DateTime.Now) { return(Json(new { objectAddedName = user.Code, valid = false, Message = CustomMessages.ErrorMessage("Beginning date must be greater than now...") })); } if (user.DateEnd < DateTime.Now) { return(Json(new { objectAddedName = user.Code, valid = false, Message = CustomMessages.ErrorMessage("Expiration date must be greater than now...") })); } if (user.DateEnd <= user.DateBegin) { return(Json(new { objectAddedName = user.Code, valid = false, Message = CustomMessages.ErrorMessage("Expiration date must follow Beginning Date") })); } if (Count <= 0) { return(Json(new { objectAddedName = user.Code, valid = false, Message = CustomMessages.ErrorMessage("Count Must be greater than 0") })); } if (Count > 200) { return(Json(new { objectAddedName = user.Code, valid = false, Message = CustomMessages.ErrorMessage("Count must be less than 200") })); } List <tCoupon> res = CreateCouponsMultiple(user, Count); _couponRepository.Insert(res); return(Json(new { objectAddedName = user.Code, valid = true, Message = CustomMessages.SuccessMessage("Coupons were added Succesfully") })); } return(Json(new { objectAddedName = "", valid = false, Message = CustomMessages.ErrorMessage("Fill All Fields please") })); }
public void Delete(int id) { tCoupon user = Find(id); if (user != null && user.IDCoupon > 0) { context.tCoupons.DeleteOnSubmit(user); } context.SubmitChanges(); }
private List <tCoupon> CreateCouponsMultiple(tCoupon user, int Count) { List <tCoupon> res = new List <tCoupon>(); for (int i = 0; i < Count; i++) { string Finalcode = GenerateRandomCode(16); tCoupon couponToCreate = new tCoupon(); couponToCreate.IDPartner = user.IDPartner; couponToCreate.Code = user.Code; couponToCreate.CustomCode = Finalcode; couponToCreate.CouponValue = user.CouponValue; couponToCreate.DateBegin = user.DateBegin; couponToCreate.DateEnd = user.DateEnd; couponToCreate.DateAdded = user.DateAdded; couponToCreate.CouponStatus = (int)Enums.enmCouponStatus.Unused; res.Add(couponToCreate); } return(res); }
private tCoupon ValidateCoupon(CouponConsumeModel couponData) { tCoupon coupon = _coupoRepository.FindByCustomNo(couponData.CouponNo); if (coupon == null) { ModelState.AddModelError("Coupon", "Coupon Not Found!"); return(coupon); } int UserID = (int)MembershipHelper.GetCurrenUser().ProviderUserKey; if (coupon.IDPartner != UserID) { ModelState.AddModelError("Coupon", "User is Wrong For this Coupon!"); return(coupon); } if (coupon.Code != couponData.CouponCode) { ModelState.AddModelError("Coupon", "Coupon Code Not Valid!"); return(coupon); } return(coupon); }
public void InsertOrUpdate(tCoupon user) { if (user.IDCoupon == default(int)) { // New entity context.tCoupons.InsertOnSubmit(user); } else { // Existing entity tCoupon userToUpdate = Find(user.IDCoupon); if (userToUpdate != null && userToUpdate.IDCoupon > 0) { userToUpdate.IDPartner = user.IDPartner; userToUpdate.Code = user.Code; userToUpdate.CouponValue = user.CouponValue; userToUpdate.DateBegin = user.DateBegin; userToUpdate.DateEnd = user.DateEnd; userToUpdate.DateAdded = user.DateAdded; userToUpdate.CouponStatus = user.CouponStatus; userToUpdate.ConsumeStatus = user.ConsumeStatus; } } }
public ActionResult SMSMessageApprove(PaymentResultModel inputModel) { int UserID = (int)MembershipHelper.GetCurrenUser().ProviderUserKey; PaymentResultModel resModel = new PaymentResultModel(); resModel = inputModel; tPaymentMessage msg = _paymentMessageRepository.Find(inputModel.SMSUniqueID); if (msg == null) { resModel.PaymentStatus = false; resModel.StatusMessage += "SMS Code not found :" + msg.UniqueID; ModelState.AddModelError("SMSStatus", resModel.StatusMessage); return(View("MakePayment", inputModel)); } if (inputModel.PaymentCode != msg.SMSCode) { resModel.PaymentStatus = false; resModel.StatusMessage += "SMS Code is wrong :" + msg.UniqueID; ModelState.AddModelError("SMSStatus", resModel.StatusMessage); return(View("MakePayment", inputModel)); } tDeal currentDeal = _dealRepository.Find(inputModel.IDDeal); ValidateDeal(currentDeal); if (!ModelState.IsValid) { resModel.PaymentStatus = false; resModel.StatusMessage += "Deal Error"; ModelState.AddModelError("SMSStatus", resModel.StatusMessage); return(View("MakePayment", inputModel)); } List <tCoupon> couponsForThisPartner = _couponRepository.GetListByIDPartnerNotUsedAndNotConsumed(currentDeal.IDPartner); if (couponsForThisPartner == null || couponsForThisPartner.Count == 0) { resModel.PaymentStatus = false; resModel.StatusMessage += "Coupon info could't be found, please contact web admin"; ModelState.AddModelError("SMSStatus", resModel.StatusMessage); return(View("MakePayment", inputModel)); } tCoupon currCouponToUse = couponsForThisPartner[0]; resModel.CouponCode = currCouponToUse.CustomCode; currCouponToUse.CouponStatus = (int)Enums.enmCouponStatus.Used; decimal AmountToBePaid = CalculateAmountToBePaid(currentDeal, inputModel.Quantity); if (AmountToBePaid <= 0) { resModel.PaymentStatus = false; resModel.StatusMessage += "Please verify amount to be paid for this deal!"; ModelState.AddModelError("SMSStatus", resModel.StatusMessage); return(View("MakePayment", inputModel)); } resModel.StatusMessage = "Your Order has been approved succesfully!"; resModel.PaymentStatus = true; _couponRepository.InsertOrUpdate(currCouponToUse); tOrder order = new tOrder(); order.AmountPaid = AmountToBePaid; order.BuyerNotes = CommonUtils.Instance.ShoppingCart.BuyerNotes; order.IDCoupon = currCouponToUse.IDCoupon; order.IDDeal = currentDeal.IDDeal; order.IDUserBought = UserID; order.MobilePhoneNo = CommonUtils.Instance.ShoppingCart.MobilePhone; order.OrderNotes = CommonUtils.Instance.ShoppingCart.OrderNotes; order.OrderStatus = (int)Enums.enmOrderStatus.ToBePaid; order.PaymentType = (int)Enums.enmPaymentType.BeelineKG; order.Quantity = CommonUtils.Instance.ShoppingCart.Quantity; order.RefundStatus = (int)Enums.enmRefundStatus.OrderSuccessful; _orderRepository.InsertOrUpdate(order); if (resModel.PaymentStatus) { _orderRepository.Save(); _couponRepository.Save(); } return(View(resModel)); }
public ActionResult MakePayment(tDealBuyModel currentCheckoutData) { currentCheckoutData.Quantity = CommonUtils.Instance.ShoppingCart.Quantity; currentCheckoutData.BuyerNotes = CommonUtils.Instance.ShoppingCart.BuyerNotes; currentCheckoutData.MobilePhone = CommonUtils.Instance.ShoppingCart.MobilePhone; PaymentResultModel resModel = new PaymentResultModel(); resModel.IDDeal = currentCheckoutData.IDDeal; int UserID = (int)MembershipHelper.GetCurrenUser().ProviderUserKey; tOrder ordData = _orderRepository.GetOrderByIDDealIDUser(currentCheckoutData.IDDeal, UserID); tDeal currentDeal = _dealRepository.Find(currentCheckoutData.IDDeal); tDealBuyModel buyModel = GetBuyModel(currentDeal); if (ordData != null && ordData.tCoupon.ConsumeStatus == (int)Enums.enmCouponConsumeStatus.NotConsumed) { resModel.PaymentStatus = false; resModel.StatusMessage += "You have already bought this deal, please use it's coupon and try again"; ModelState.AddModelError("Error", resModel.StatusMessage); return(View("Checkout", buyModel)); } ValidateDeal(currentDeal); if (!ModelState.IsValid) { resModel.PaymentStatus = false; resModel.StatusMessage += "Deal Error"; ModelState.AddModelError("Error", resModel.StatusMessage); return(View("Checkout", buyModel)); } if (currentCheckoutData.Quantity < currentDeal.QuantityMinimum) { resModel.PaymentStatus = false; resModel.StatusMessage += "Minimum Quantity allowed :" + currentDeal.QuantityMinimum; ModelState.AddModelError("Error", resModel.StatusMessage); return(View("Checkout", buyModel)); } List <tCoupon> couponsForThisPartner = _couponRepository.GetListByIDPartnerNotUsedAndNotConsumed(currentDeal.IDPartner); if (couponsForThisPartner == null || couponsForThisPartner.Count == 0) { resModel.PaymentStatus = false; resModel.StatusMessage += "Coupon info could't be found, please contact web admin"; currentCheckoutData.currentDeal = currentDeal; ModelState.AddModelError("Error", resModel.StatusMessage); return(View("Checkout", buyModel)); } tCoupon currCouponToUse = couponsForThisPartner[0]; resModel.CouponCode = currCouponToUse.CustomCode; currCouponToUse.CouponStatus = (int)Enums.enmCouponStatus.Used; IPayment paymentAgent = new PaymentAgentBeelineKg(); decimal AmountToBePaid = CalculateAmountToBePaid(currentDeal, currentCheckoutData.Quantity); if (AmountToBePaid <= 0) { resModel.PaymentStatus = false; resModel.StatusMessage += "Please verify amount to be paid for this deal!"; ModelState.AddModelError("Error", resModel.StatusMessage); return(View("Checkout", buyModel)); } PaymentBLL pBLL = new PaymentBLL(); bool paymentResult = pBLL.MakePayment(AmountToBePaid, paymentAgent); resModel.StatusMessage = pBLL.StatusMessage; resModel.PaymentStatus = paymentResult; resModel.CouponCode = currCouponToUse.CustomCode; if (paymentAgent.GetType() == typeof(PaymentAgentBeelineKg)) { System.Guid uniqueID = Guid.NewGuid(); tPaymentMessage msg = new tPaymentMessage(); msg.UniqueID = uniqueID.ToString(); msg.IDDeal = currentCheckoutData.IDDeal; msg.IDUsed = UserID; msg.SMSCode = pBLL.PaymentCode; msg.DateAdded = DateTime.Now; msg.Approved = false; _paymentMessageRepository.InsertOrUpdate(msg); resModel.PaymentType = (int)Enums.enmPaymentType.BeelineKG; resModel.SMSUniqueID = uniqueID.ToString(); } else { //Burdan aşağısı sadece kredikartı için çalışır _couponRepository.InsertOrUpdate(currCouponToUse); tOrder order = new tOrder(); order.AmountPaid = AmountToBePaid; order.BuyerNotes = CommonUtils.Instance.ShoppingCart.BuyerNotes; order.IDCoupon = currCouponToUse.IDCoupon; order.IDDeal = currentDeal.IDDeal; order.IDUserBought = UserID; order.MobilePhoneNo = CommonUtils.Instance.ShoppingCart.MobilePhone; order.OrderNotes = currentCheckoutData.OrderNotes; CommonUtils.Instance.ShoppingCart.OrderNotes = currentCheckoutData.OrderNotes; order.OrderStatus = (int)Enums.enmOrderStatus.ToBePaid; order.PaymentType = (int)Enums.enmPaymentType.BeelineKG; order.Quantity = currentCheckoutData.Quantity; order.RefundStatus = (int)Enums.enmRefundStatus.OrderSuccessful; _orderRepository.InsertOrUpdate(order); if (paymentResult) { _orderRepository.Save(); _couponRepository.Save(); } } return(View(resModel)); }