public ActionResult PartnerDealDetails(int?IDDeal) { IDDeal = IDDeal ?? 0; tDeal dealData = _dealRepository.Find((int)IDDeal); return(View(dealData)); }
private void ValidateDeal(tDeal currentDeal) { if (currentDeal == null) { ModelState.AddModelError("DealInfo", "Deal Info couldn't be found, please contact web admin"); } if (DateTime.Now < currentDeal.DateStarting) { ModelState.AddModelError("DealInfo", "Deal has not started yet."); } if (DateTime.Now > currentDeal.DateEnding) { ModelState.AddModelError("DealInfo", "Deal is over."); } //if (currentCheckoutData.Quantity > currentDeal.LimitUpper) { // resModel.PaymentStatus = false; // resModel.StatusMessage += "Maximum Amount allowed :" + currentDeal.LimitUpper; // return View(resModel); //} //if (currentCheckoutData.Quantity < currentDeal.LimitLower) { // resModel.PaymentStatus = false; // resModel.StatusMessage += "Minimum Amount allowed :" + currentDeal.LimitUpper; // return View(resModel); //} }
private void ArrangeImages(tDeal dealData) { HttpPostedFileBase ProductImage = Request.Files["ProductImage"]; HttpPostedFileBase ProductImage1 = Request.Files["ProductImage1"]; HttpPostedFileBase ProductImage2 = Request.Files["ProductImage2"]; if (ProductImage.ContentLength > 0) { var fileName = Path.GetFileName(ProductImage.FileName); var path = Path.Combine(Server.MapPath("~/Images/Deal"), fileName); ProductImage.SaveAs(path); dealData.ProductImage = fileName; } if (ProductImage1.ContentLength > 0) { var fileName = Path.GetFileName(ProductImage1.FileName); var path = Path.Combine(Server.MapPath("~/Images/Deal"), fileName); ProductImage1.SaveAs(path); dealData.ProductImage1 = fileName; } if (ProductImage2.ContentLength > 0) { var fileName = Path.GetFileName(ProductImage2.FileName); var path = Path.Combine(Server.MapPath("~/Images/Deal"), fileName); ProductImage2.SaveAs(path); dealData.ProductImage2 = fileName; } }
public WrappedJsonResult EditAjax(tDeal dealData) { if (ModelState.IsValid) { ArrangeCityData(dealData); ArrangeImages(dealData); _dealRepository.InsertOrUpdate(dealData); return(new WrappedJsonResult { Data = new { objectAddedName = "", valid = true, Message = CustomMessages.SuccessMessage("tDeal Updated Succesfully") } }); } else { return(new WrappedJsonResult { Data = new { objectAddedName = "", valid = false, Message = CustomMessages.ErrorMessage("Fill All Fields please") } }); } }
public ActionResult Index() { if (MembershipHelper.CurrentCity == null || MembershipHelper.CurrentCity.IDCategory == 0) { tCategory cat = _categoryRepository.GetListByIDCategoryType((int)Enums.enmCategoryTypes.City). FirstOrDefault(); if (cat == null) { cat = new tCategory() { Name = "City Not Found", IDCategory = 0 } } ; MembershipHelper.CurrentCity = cat; } tDeal currentDeal = _dealRepository.GetLatestDeal(MembershipHelper.CurrentCity.IDCategory); ViewBag.LeftTSStr = tDealUtils.GetLeftTSStrForDeal(currentDeal); if (currentDeal == null) { currentDeal = new tDeal(); } if (MembershipHelper.CurrentCity != null && currentDeal != null) { ViewBag.DealsBySameCategory = _dealRepository.GetListByIDCategory(currentDeal.IDDealCategory).Take(6).OrderByDescending(t => t.DateAdded).ToList(); } else { ViewBag.DealsBySameCategory = new List <tDeal>(); } return(View(currentDeal)); }
public static bool DealIsActive(tDeal deal) { if (deal.DateEnding < DateTime.Now) { return(false); } return(true); }
public static string DiscountStr(tDeal deal) { decimal currPrice = deal.DealPrice; decimal marketPrice = deal.MarketPrice; decimal discount = 100 - ((currPrice * 100) / marketPrice); discount = Math.Ceiling(discount); return(String.Format("{0:0.##} %", discount)); }
public WrappedJsonResult CreateAjax(tDeal dealData) { if (ModelState.IsValid) { ArrangeCityData(dealData); ArrangeImages(dealData); dealData.DateAdded = DateTime.Now; if (dealData.DateStarting < DateTime.Now) { return new WrappedJsonResult { Data = new { objectAddedName = dealData.DealTitle, valid = false, Message = CustomMessages.ErrorMessage("DateStarting must be greater than now...") } } } ; if (dealData.DateEnding < DateTime.Now) { return new WrappedJsonResult { Data = new { objectAddedName = dealData.DealTitle, valid = false, Message = CustomMessages.ErrorMessage("DateEnding must be greater than now...") } } } ; if (dealData.DateEnding <= dealData.DateStarting) { return new WrappedJsonResult { Data = new { objectAddedName = dealData.DealTitle, valid = false, Message = CustomMessages.ErrorMessage("DateEnding must follow Beginning Date") } } } ; _dealRepository.InsertOrUpdate(dealData); return(new WrappedJsonResult { Data = new { objectAddedName = dealData.DealTitle, valid = true, Message = CustomMessages.SuccessMessage("Deal was added Succesfully") } }); } return(new WrappedJsonResult { Data = new { objectAddedName = "", valid = false, Message = CustomMessages.ErrorMessage("Fill All Fields please") } }); }
private tDealBuyModel GetBuyModel(tDeal currentDeal) { tDealBuyModel buyModel = new tDealBuyModel(); buyModel.currentDeal = currentDeal; buyModel.Quantity = CommonUtils.Instance.ShoppingCart.Quantity; buyModel.BuyerNotes = CommonUtils.Instance.ShoppingCart.BuyerNotes; buyModel.MobilePhone = CommonUtils.Instance.ShoppingCart.MobilePhone; return(buyModel); }
public static string GetLeftTSStrForDeal(tDeal deal) { if (deal.DateEnding < DateTime.Now) { return("Deal Is Over"); } TimeSpan ts = deal.DateEnding - DateTime.Now; return(ts.Days + " days " + ts.Hours + " hrs " + ts.Minutes + " min " + ts.Seconds + " sec"); }
public ActionResult Edit(int id) { ViewBag.userData = _userRepository.GetListByIDRole((int)Enums.enmRoles.Partner); ViewBag.groupData = _groupRepository.All; ViewBag.categoryData = _categoryRepository.GetListByIDCategoryType((int)Enums.enmCategoryTypes.DealCategory); ViewBag.possibleCities = _categoryRepository.GetListByIDCategoryType((int)Enums.enmCategoryTypes.City); tDeal currentDeal = _dealRepository.Find(id); return(View(currentDeal)); }
public ActionResult Details(int?id) { if (id == null) { id = 0; } tDeal deal = _dealRepository.Find((int)id); ViewBag.LeftTSStr = tDealUtils.GetLeftTSStrForDeal(deal); ViewBag.DealsBySameCategory = _dealRepository.GetListByIDCategory(deal.IDDealCategory).Take(6).OrderByDescending(t => t.DateAdded).ToList(); return(View(deal)); }
public ActionResult Buy(int?id) { if (id == null) { id = 0; } tDealBuyModel finalmodel = new tDealBuyModel(); tDeal deal = _dealRepository.Find((int)id); finalmodel.currentDeal = deal; finalmodel.Quantity = deal.QuantityMinimum; finalmodel.IDDeal = (int)id; return(View(finalmodel)); }
public void Delete(int id) { tDeal user = Find(id); if (user != null && user.IDDeal > 0) { for (int i = 0; i < user.tDealCities.Count; i++) { context.tDealCities.DeleteOnSubmit(user.tDealCities[i]); } context.tDeals.DeleteOnSubmit(user); } context.SubmitChanges(); }
public ActionResult Checkout() { int IDDeal = CommonUtils.Instance.ShoppingCart.IDDeal; tDeal currentDeal = _dealRepository.Find(IDDeal); tDealBuyModel buyModel = new tDealBuyModel(); buyModel.currentDeal = currentDeal; buyModel.IDDeal = IDDeal; buyModel.Quantity = CommonUtils.Instance.ShoppingCart.Quantity; buyModel.BuyerNotes = CommonUtils.Instance.ShoppingCart.BuyerNotes; buyModel.MobilePhone = CommonUtils.Instance.ShoppingCart.MobilePhone; //if (id == null) id = 0; //tDeal deal = _dealRepository.Find((int)id); //return View(deal); return(View(buyModel)); }
private void ArrangeCityData(tDeal dealData) { if (dealData.HelperString != null) { string[] arr = dealData.HelperString.Split(','); if (arr.Length > 0) { int[] intArr = new int[arr.Length]; for (int i = 0; i < intArr.Length; i++) { dealData.tDealCities.Add(new tDealCity { IDCity = int.Parse(arr[i]), IDDeal = dealData.IDDeal }); } } dealData.HelperString = null; } }
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)); }
decimal CalculateAmountToBePaid(tDeal deal, int Amount) { return(deal.DealPrice * Amount); }
public void InsertOrUpdate(tDeal user) { if (user.IDDeal == default(int)) { // New entity user.DateAdded = DateTime.Now; context.tDeals.InsertOnSubmit(user); } else { // Existing entity tDeal userToUpdate = Find(user.IDDeal); if (userToUpdate != null && userToUpdate.IDDeal > 0) { userToUpdate.AllowRefundFlag = user.AllowRefundFlag; userToUpdate.BiggestCardUse = user.BiggestCardUse; userToUpdate.ConsumerRebates = user.ConsumerRebates; userToUpdate.DateCouponExpiry = user.DateCouponExpiry; userToUpdate.DateEnding = user.DateEnding; if (userToUpdate.tDealCities.Count > 0) { for (int i = 0; i < userToUpdate.tDealCities.Count; i++) { context.tDealCities.DeleteOnSubmit(userToUpdate.tDealCities[i]); } context.SubmitChanges(); userToUpdate.tDealCities = user.tDealCities; } userToUpdate.DateStarting = user.DateStarting; userToUpdate.DealPrice = user.DealPrice; userToUpdate.DealTitle = user.DealTitle; userToUpdate.Detail = user.Detail; userToUpdate.FlvVideoFile = user.FlvVideoFile; userToUpdate.IDDealCategory = user.IDDealCategory; userToUpdate.IDDealType = user.IDDealType; userToUpdate.IDGroup = user.IDGroup; userToUpdate.IDPartner = user.IDPartner; userToUpdate.Introduction = user.Introduction; userToUpdate.InvitationRebate = user.InvitationRebate; userToUpdate.LimitLower = user.LimitLower; userToUpdate.LimitUpper = user.LimitUpper; userToUpdate.LimitUser = user.LimitUser; userToUpdate.MarketPrice = user.MarketPrice; userToUpdate.ModeOfDelivery = user.ModeOfDelivery; userToUpdate.PrductName = user.PrductName; userToUpdate.ProductImage = user.ProductImage; userToUpdate.ProductImage1 = user.ProductImage1; userToUpdate.ProductImage2 = user.ProductImage2; userToUpdate.ProductOptions = user.ProductOptions; userToUpdate.QuantityMinimum = user.QuantityMinimum; userToUpdate.SortOrder = user.SortOrder; userToUpdate.Tips = user.Tips; userToUpdate.UserReviews = user.UserReviews; userToUpdate.VirtualBuyers = user.VirtualBuyers; } } context.SubmitChanges(); }
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)); }