예제 #1
0
        public ActionResult GetCoupon(long id, string subdomain)
        {
            var storeSetting = new SessionHelpers().GetStoreInfo(subdomain);

            if (storeSetting == null || storeSetting.StoreId < 1)
            {
                return(Json(new List <ChildMenuObject>(), JsonRequestBehavior.AllowGet));
            }
            try
            {
                if (id < 1)
                {
                    return(Json(new CouponObject(), JsonRequestBehavior.AllowGet));
                }

                var coupon = new CouponServices().GetCoupon(id);
                if (id < 1)
                {
                    return(Json(new CouponObject(), JsonRequestBehavior.AllowGet));
                }
                Session["_coupon"] = coupon;
                return(Json(coupon, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new CouponObject(), JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public ActionResult GetCouponObjects(JQueryDataTableParamModel param, string subdomain)
        {
            var storeSetting = new SessionHelpers().GetStoreInfo(subdomain);

            if (storeSetting == null || storeSetting.StoreId < 1)
            {
                return(Json(new List <ChildMenuObject>(), JsonRequestBehavior.AllowGet));
            }
            try
            {
                IEnumerable <CouponObject> filteredCouponObjects;
                var countG = new CouponServices().GetObjectCount();

                var pagedCouponObjects = GetCoupons(param.iDisplayLength, param.iDisplayStart);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredCouponObjects = new CouponServices().Search(param.sSearch);
                }
                else
                {
                    filteredCouponObjects = pagedCouponObjects;
                }

                if (!filteredCouponObjects.Any())
                {
                    return(Json(new List <CouponObject>(), JsonRequestBehavior.AllowGet));
                }

                var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <CouponObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.Title : c.Code
                                                                );

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredCouponObjects = sortDirection == "asc" ? filteredCouponObjects.OrderBy(orderingFunction) : filteredCouponObjects.OrderByDescending(orderingFunction);

                var displayedUserProfilenels = filteredCouponObjects;

                var result = from c in displayedUserProfilenels
                             select new[] { Convert.ToString(c.CouponId), c.Title, c.Code, c.PercentageDeduction.ToString(CultureInfo.InvariantCulture), c.MinimumOrderAmount.ToString(CultureInfo.InvariantCulture), c.ValidityPeriod };
                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = filteredCouponObjects.Count(),
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <CouponObject>(), JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
        public UnitOfWork(ApplicationDbContext db, IHttpContextAccessor httpContextAccessor, IEmailSender emailSender)
        {
            _db = db;
            _httpContextAccessor = httpContextAccessor;
            _emailSender         = emailSender;

            Category            = new CategoryServices(db);
            SubCategory         = new SubCategoryServices(db);
            Coupon              = new CouponServices(db);
            User                = new UserServices(db, httpContextAccessor);
            MenuItem            = new MenuItemServices(db);
            ShoppingCart        = new ShoppingCartServices(db);
            OrderServices       = new OrderServices(db, emailSender);
            OrderDetailServices = new OrderDetailServices(db);
        }
예제 #4
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));
            }
        }
예제 #5
0
        public ActionResult DeleteCoupon(long id, 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
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = message_Feedback.Invalid_Selection;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new CouponServices().DeleteCoupon(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Delete_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Delete_Failure;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
예제 #6
0
        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));
            }
        }