public int UpdateCoupon(CouponObject coupon) { try { if (coupon == null) { return(-2); } var duplicates = _repository.Count(m => m.Title.Trim().ToLower() == coupon.Code.Trim().ToLower() && m.ValidFrom == coupon.ValidFrom && m.ValidTo == coupon.ValidTo && (m.CouponId != coupon.CouponId)); if (duplicates > 0) { return(-3); } var couponEntity = ModelCrossMapper.Map <CouponObject, Coupon>(coupon); if (couponEntity == null || couponEntity.CouponId < 1) { return(-2); } _repository.Update(couponEntity); _uoWork.SaveChanges(); return(5); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public long AddCoupon(CouponObject coupon) { try { if (coupon == null) { return(-2); } var duplicates = _repository.Count(m => m.Title.Trim().ToLower() == coupon.Code.Trim().ToLower() && m.ValidFrom == coupon.ValidFrom && m.ValidTo == coupon.ValidTo); if (duplicates > 0) { return(-3); } var couponEntity = ModelCrossMapper.Map <CouponObject, Coupon>(coupon); if (couponEntity == null || string.IsNullOrEmpty(couponEntity.Title)) { return(-2); } var returnStatus = _repository.Add(couponEntity); _uoWork.SaveChanges(); return(returnStatus.CouponId); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
private void addObjectToList(CouponObject couponObject) { List <CouponObject> objects = ViewState["objects"] != null ? ((List <CouponObject>)ViewState["objects"]) : new List <CouponObject>(); objects.Add(couponObject); ViewState["objects"] = objects; showObjects(); }
public int UpdateCoupon(CouponObject coupon) { try { return(_couponRepository.UpdateCoupon(coupon)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public long AddCoupon(CouponObject coupon) { try { return(_couponRepository.AddCoupon(coupon)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult AddCoupon(CouponObject coupon, string subdomain) { var storeSetting = new SessionHelpers().GetStoreInfo(subdomain); if (storeSetting == null || storeSetting.StoreId < 1) { return(Json(new List <ChildMenuObject>(), JsonRequestBehavior.AllowGet)); } var gVal = new GenericValidator(); try { var valStatus = ValidateCoupon(coupon); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new CouponServices().AddCoupon(coupon); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 0; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateCoupon(CouponObject coupon) { var gVal = new GenericValidator(); if (coupon == null) { gVal.Code = -1; gVal.Error = message_Feedback.Fatal_Error; return(gVal); } if (string.IsNullOrEmpty(coupon.Title)) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Title_Error; return(gVal); } if (string.IsNullOrEmpty(coupon.Code)) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Code_Error; return(gVal); } if (coupon.PercentageDeduction < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Percentage_Deduction_Error; return(gVal); } if (coupon.MinimumOrderAmount < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Minimum_Order_Amount_Error; return(gVal); } if (coupon.ValidFrom.Year == 1) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Valid_From_Error; return(gVal); } if (coupon.ValidFrom < DateTime.Today) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Valid_From_Less_Error; return(gVal); } if (coupon.ValidTo.Year == 1) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Valid_To_Error; return(gVal); } if (coupon.ValidTo < DateTime.Today) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Valid_To_Less_Error; return(gVal); } if (coupon.ValidTo < coupon.ValidFrom) { gVal.Code = -1; gVal.Error = message_Feedback.Coupon_Validity_Error; return(gVal); } gVal.Code = 5; return(gVal); }
public ActionResult EditCoupon(CouponObject coupon, string subdomain) { var storeSetting = new SessionHelpers().GetStoreInfo(subdomain); if (storeSetting == null || storeSetting.StoreId < 1) { return(Json(new List <ChildMenuObject>(), JsonRequestBehavior.AllowGet)); } var gVal = new GenericValidator(); try { var valStatus = ValidateCoupon(coupon); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_coupon"] == null) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldCoupon = Session["_coupon"] as CouponObject; if (oldCoupon == null || oldCoupon.CouponId < 1) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldCoupon.Title = coupon.Title.Trim(); oldCoupon.Code = coupon.Code.Trim(); oldCoupon.PercentageDeduction = coupon.PercentageDeduction; oldCoupon.MinimumOrderAmount = coupon.MinimumOrderAmount; oldCoupon.ValidFrom = coupon.ValidFrom; oldCoupon.ValidTo = coupon.ValidTo; var k = new CouponServices().UpdateCoupon(oldCoupon); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 0; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public CouponObject ValidateCoupon(string coupon) { var returnValues = new CouponObject(); var rtv = repoCoupon.GetNonAsync(o => o.CouponCode == coupon); if (rtv != null) { var rtn = repoCouponAssign.GetNonAsync(o => o.CouponCode == coupon); if (rtn != null) { var setUp = repoCouponSetUp.GetNonAsync(null); if (setUp != null) { if (setUp.TimeBased == "D") { if (DateTime.Now <= setUp.DateCreated.Value.AddDays(Convert.ToInt32(setUp.CutOffTime))) { if (setUp.CouponType == "P") { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + setUp.CouponValue + "%" + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } else { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + "N" + setUp.CouponValue + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } } } else if (setUp.TimeBased == "H") { if (DateTime.Now <= setUp.DateCreated.Value.AddHours(Convert.ToInt32(setUp.CutOffTime))) { if (setUp.CouponType == "P") { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + setUp.CouponValue + "%" + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } else { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + "N" + setUp.CouponValue + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } } } else if (setUp.TimeBased == "M") { if (DateTime.Now <= setUp.DateCreated.Value.AddMonths(Convert.ToInt32(setUp.CutOffTime))) { if (setUp.CouponType == "P") { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + setUp.CouponValue + "%" + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } else { returnValues.nErrorCode = 1; returnValues.CouponAgentId = (int)rtn.AgentID; returnValues.sErrorText = "Discount of " + "₦" + setUp.CouponValue + " has Successully Been Applied"; returnValues.CouponValue = FormattedAmount((decimal)setUp.CouponValue); return(returnValues); } } } } } } returnValues.nErrorCode = -5; returnValues.sErrorText = "Voucher Code does not Exist"; return(returnValues); }