Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CouponModel coupons)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                if (files.Count > 0)
                {
                    byte[] p1 = null;
                    using (var fs1 = files[0].OpenReadStream())
                    {
                        using (var ms1 = new MemoryStream())
                        {
                            fs1.CopyTo(ms1);
                            p1 = ms1.ToArray();
                        }
                    }
                    coupons.Picture = p1;
                }
                _dbContext.Coupon.Add(coupons);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coupons));
        }
Ejemplo n.º 2
0
        public async Task <int> AddCouponAsync(CouponModel couponModel)
        {
            _dbContext.Coupons.Add(couponModel);
            await _dbContext.SaveChangesAsync();

            return(couponModel.CouponId);
        }
Ejemplo n.º 3
0
        public static ObsoletePageModel <CouponModel> GetCouponByName(string text, DateTime endDate, int ReceiveType, int page, int pageSize)
        {
            var couponList = _iCouponService.GetCouponByName(text, endDate, ReceiveType, page, pageSize);
            var pageModel  = new ObsoletePageModel <CouponModel>();

            var lmCoupon = new List <Himall.DTO.CouponModel>();

            foreach (var item in couponList.Models.ToList())
            {
                if (item.IsSyncWeiXin == 0 || (item.IsSyncWeiXin == 1 && item.WXAuditStatus == (int)WXCardLogInfo.AuditStatusEnum.Audited))
                {
                    CouponModel couponModel = new CouponModel();
                    couponModel.CouponName  = item.CouponName;
                    couponModel.Id          = item.Id;
                    couponModel.Num         = item.Num;
                    couponModel.useNum      = item.Himall_CouponRecord.Count();
                    couponModel.inventory   = item.Num - item.Himall_CouponRecord.Count();
                    couponModel.OrderAmount = item.OrderAmount == 0 ? "不限制" : "满" + item.OrderAmount;
                    couponModel.Price       = item.Price;
                    couponModel.ShopName    = item.ShopName;
                    couponModel.EndTime     = item.EndTime;
                    couponModel.StartTime   = item.StartTime;
                    couponModel.perMax      = item.PerMax;
                    lmCoupon.Add(couponModel);
                }
            }
            pageModel.Models = lmCoupon.AsQueryable();
            pageModel.Total  = couponList.Total;
            return(pageModel);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is used to Insert update Coupon Details for Coupon Management : Created by Nishant
        /// </summary>
        /// <param name="couponDetails">it will consist of bulk coupon details with the list of no of coupons created Insert and
        /// Update will happern on two tables Coupon and Coupon Detail</param>
        /// <returns>Returns the bool as Saved as true and not saved as false</returns>
        public bool SaveCoupon(CouponModel couponDetails)
        {
            bool isSaved = false;

            try
            {
                if (couponDetails.Id > 0)
                {
                    var coupons = _couponManagmentRepository.GetCoupons(couponDetails.CompanyCode, couponDetails.BranchCode).FirstOrDefault(x => x.Id == couponDetails.Id);
                    SetCouponValuesBeforeSave(couponDetails, coupons);
                    _couponManagmentRepository.SaveCouponDetails(coupons);
                    isSaved = true;
                    ///Code for EDIT COUPONS
                }
                else
                {
                    ///Code for Add Coupon
                    Coupon objCoupon = new Coupon();
                    SetCouponValuesBeforeSave(couponDetails, objCoupon);
                    int CouponId = _couponManagmentRepository.SaveCouponDetails(objCoupon);
                    isSaved = SaveCouponDetails(couponDetails, CouponId);
                }
                return(isSaved);
            }
            catch (Exception ex)
            {
                fault.Result       = false;
                fault.ErrorMessage = "Error in SaveCouponDetails method";
                fault.ErrorDetails = ex.ToString();
                throw new FaultException <FaultData>(fault);
            }
        }
Ejemplo n.º 5
0
        public JsonResult Create([System.Web.Http.FromBody] CouponModel m)
        {
            List <CouponResponseModel> response = new List <CouponResponseModel>();

            try
            {
                m.name       = m.name?.Trim() ?? "";
                m.couponcode = m.couponcode?.Trim() ?? "";
                if (m.couponcode.HasValue())
                {
                    if (CouponModel.IsExisting(m.couponcode))
                    {
                        response.Add(new CouponResponseModel {
                            Message = "code already exists"
                        });
                        return(Json(response, JsonRequestBehavior.AllowGet));
                    }
                }

                m.CreateCoupon();
                response.Add(new CouponResponseModel {
                    Message = "Ok"
                });
            }
            catch (Exception ex)
            {
                response.Add(new CouponResponseModel {
                    Message = ex.Message
                });
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public ActionResult Index(string CouponCode)
        {
            CouponCode = CouponCode.Trim().Replace(" ", "");
            CouponModel model = new CouponModel();
            var         cart  = (CartModel)System.Web.HttpContext.Current.Session["cart"];

            var coupon = model.GetList().FirstOrDefault(m => m.CouponCode == CouponCode);


            if (coupon != null)
            {
                cart.CouponApplied = true;
                cart.CouponId      = coupon.CouponId;
                cart.CouponCode    = coupon.CouponCode;


                cart.Price = cart.Price - cart.Price * 20 / 100;
                cart.Total = cart.Price * cart.Quantity;
                System.Web.HttpContext.Current.Session["cart"] = cart;

                ViewBag.Message = "Coupon is applied Successfully";
            }
            else
            {
                ViewBag.Message = "Coupon not found or Expired!";
            }

            return(View(cart));
        }
Ejemplo n.º 7
0
        public ApiResult GetCouponList(int pageNo = 1, int limit = 10)
        {
            var result = new ApiResult();
            int totalCount;
            var coupon = _couponService.GetListPaged(pageNo, limit, c => c.Status == CouponStatus.Enable,
                                                     c => c.CreateTime, true, out totalCount);

            var resCoupons = new List <CouponModel>();

            foreach (var item in coupon)
            {
                var resCoupon = new CouponModel(item);
                if (AuthorizedUser == null)
                {
                    resCoupon.IsOwn = false;
                }
                else
                {
                    //判断是否已经领取
                    var couponRelation = _currencyService.GetSingleByConditon <CouponRelation>(c => c.CouponId == item.Id && c.MemberId == AuthorizedUser.Id);
                    resCoupon.IsOwn = couponRelation != null;
                }

                resCoupons.Add(resCoupon);
            }

            var data = new
            {
                TotalCount = totalCount,
                Coupons    = resCoupons
            };

            result.SetData(data);
            return(result);
        }
Ejemplo n.º 8
0
        public string GetCouponDetailsById(int Id)
        {
            CouponModel couponModel = new CouponModel();

            couponModel = _service.CouponRepository.GetCouponDetailsById(Id);
            return(JsonConvert.SerializeObject(couponModel));
        }
Ejemplo n.º 9
0
        public ActionResult Save(CouponModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.EncryptedID.IsValidEncryptedID() && model.EncryptedID.ToDecrypt().IsNumber())
                    {
                        model.CouponID = Convert.ToInt32(model.EncryptedID.ToDecrypt());
                    }

                    model = _Coupon.Save(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("Coupon", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 10
0
        public CouponModel Get(Guid id)
        {
            var entity = _CouponService.GetCouponById(id);
            var model  = new CouponModel
            {
                Id = entity.Id,

                Guid = entity.Guid,

                Type = entity.Type,

                DisCount = entity.DisCount,

//		        Product = entity.Product,

                ExpireTime = entity.ExpireTime,

                Status = entity.Status,

                Adduser = entity.Adduser,

                Addtime = entity.Addtime,

                Upduser = entity.Upduser,

                Updtime = entity.Updtime,

                Owner = entity.Owner,
            };

            return(model);
        }
Ejemplo n.º 11
0
 private void EnableUC(dynamic row, string callingPage)
 {
     if (callingPage == (string)Application.Current.Resources["Coupons_leftHeader"])
     {
         EnableDisableUC(Visibility.Visible, Visibility.Collapsed);
         CouponModel coupanmodel = new CouponModel(row.Id, "Edit Coupon", row.DiscountType, row.FromDate, row.ToDate, row.Value, row.NoOfCoupons, row.Name);
         objCouponDetails = _CouponManagmentControllers.GetCouponDetails(row.Id);
         lstCouponsDetails.ItemsSource = objCouponDetails;
         this.UCManageCoupon.SetText(coupanmodel);
     }
     else if (callingPage == (string)Application.Current.Resources["Offers_leftHeader"])
     {
         lstCouponsDetails.Visibility = Visibility.Collapsed;
         EnableDisableUC(Visibility.Collapsed, Visibility.Visible);
         if (row.OfferType != Utility.CommonMethods.CommonFunctions.GetDescriptionFromEnumValue(
                 (Utility.CommonEnums.CommonEnum.OfferType)Enum.Parse(typeof(Utility.CommonEnums.CommonEnum.OfferType), Convert.ToString((int)Utility.CommonEnums.CommonEnum.OfferType.ItemSpecific))))
         {
             OfferModel offerModel = new OfferModel(row.Id, "Edit Offer", row.OfferType, row.FromDate, row.ToDate, row.Discount, row.MinimumValue, row.Name);
             this.UCMangeOffer.SetText(offerModel);
         }
         else
         {
             OfferModel offerModel = new OfferModel(row.Id, "Edit Offer", row.Name);
             this.UCMangeOffer.SetItemSpecificValues(offerModel);
         }
     }
 }
Ejemplo n.º 12
0
        public bool Post(CouponModel model)
        {
            var entity = new CouponEntity
            {
                Guid = model.Guid,

                Type = model.Type,

                DisCount = model.DisCount,

//				Product = model.Product,

                ExpireTime = model.ExpireTime,

                Status = model.Status,

                Adduser = model.Adduser,

                Addtime = model.Addtime,

                Upduser = model.Upduser,

                Updtime = model.Updtime,

                Owner = model.Owner,
            };

            if (_CouponService.Create(entity).Id > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
        public bool ApplyCouponToBasket(Guid basketId, CouponModel coupon)
        {
            var basket = GetBasket(basketId);

            if (basket == null)
            {
                throw new ArgumentNullException("Basket is not found");
            }

            if (coupon != null && basket.SubTotal >= coupon.MinBasketPrice)
            {
                decimal couponDiscount = decimal.Zero;
                switch (coupon.Type)
                {
                case CouponType.Rate:
                    couponDiscount = (basket.SubTotal * coupon.Amount) / 100;
                    break;

                case CouponType.Total:
                    couponDiscount = coupon.Amount;
                    break;
                }

                basket.CouponTotal += couponDiscount;

                basket.Coupons.Add(coupon);

                return(true);
            }
            Console.WriteLine("Coupon could not be applied to basket");
            return(false);
        }
Ejemplo n.º 14
0
        public JsonResult Cancel([System.Web.Http.FromBody] string id)
        {
            List <CouponResponseModel> response = new List <CouponResponseModel>();

            try
            {
                var c = CurrentDatabase.Coupons.SingleOrDefault(cp => cp.Id == id);
                if (!c.Canceled.HasValue)
                {
                    c.Canceled = DateTime.Now;
                    CurrentDatabase.SubmitChanges();
                }
                var m = new CouponModel();

                response.Add(new CouponResponseModel {
                    Message = "Ok"
                });
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                response.Add(new CouponResponseModel {
                    Message = ex.Message
                });
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
 public async Task Delete(CouponModel couponModel)
 {
     _context.Entry(couponModel).Property(x => x.upd_dt).IsModified   = true;
     _context.Entry(couponModel).Property(x => x.upd_user).IsModified = true;
     _context.Entry(couponModel).Property(x => x.use_yn).IsModified   = true;
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 16
0
 public static double DiscountedPrice(CouponModel couponFromDb, double originalOrderTotal)
 {
     if (couponFromDb == null)
     {
         return(originalOrderTotal);
     }
     else
     {
         if (couponFromDb.MinimumAmount > originalOrderTotal)
         {
             return(originalOrderTotal);
         }
         else
         {
             //everything is valid
             if (Convert.ToInt32(couponFromDb.CouponType) == (int)CouponModel.ECoupounType.Dollar)
             {
                 //$10 off $100
                 return(Math.Round(originalOrderTotal - couponFromDb.Discount, 2));
             }
             if (Convert.ToInt32(couponFromDb.CouponType) == (int)CouponModel.ECoupounType.Percent)
             {
                 //10% off $100
                 return(Math.Round(originalOrderTotal - (originalOrderTotal * couponFromDb.Discount / 100), 2));
             }
         }
     }
     return(originalOrderTotal);
 }
Ejemplo n.º 17
0
        public static QueryPageModel <CouponModel> GetCouponByName(string text, DateTime endDate, int ReceiveType, int page, int pageSize)
        {
            var couponList = Service.GetCouponByName(text, endDate, ReceiveType, page, pageSize);
            var pageModel  = new QueryPageModel <CouponModel>();

            var lmCoupon = new List <CouponModel>();
            var records  = Service.GetRecordCountByCoupon(couponList.Models.Select(p => p.Id).ToList());

            foreach (var item in couponList.Models)
            {
                if (item.IsSyncWeiXin == 0 || (item.IsSyncWeiXin == 1 && item.WXAuditStatus == (int)WXCardLogInfo.AuditStatusEnum.Audited))
                {
                    var         record      = records.ContainsKey(item.Id) ? records[item.Id] : 0;
                    CouponModel couponModel = new CouponModel();
                    couponModel.CouponName  = item.CouponName;
                    couponModel.Id          = item.Id;
                    couponModel.Num         = item.Num;
                    couponModel.useNum      = record;
                    couponModel.inventory   = item.Num - record;
                    couponModel.OrderAmount = item.OrderAmount == 0 ? "不限制" : "满" + item.OrderAmount;
                    couponModel.Price       = item.Price;
                    couponModel.ShopName    = item.ShopName;
                    couponModel.EndTime     = item.EndTime;
                    couponModel.StartTime   = item.StartTime;
                    couponModel.perMax      = item.PerMax;
                    couponModel.UseArea     = item.UseArea;
                    couponModel.Remark      = item.Remark;
                    lmCoupon.Add(couponModel);
                }
            }
            pageModel.Models = lmCoupon;
            pageModel.Total  = couponList.Total;
            return(pageModel);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// to get page full detail
        /// </summary>
        /// <param name="encryptedId"></param>
        /// <returns></returns>
        public CouponModel GetDetail(string encryptedId)
        {
            CouponModel model = new CouponModel();

            try
            {
                int CouponId = Convert.ToInt32(encryptedId);
                #region get detail
                model = UnitofWork.RepoCoupon.Where(x => x.CouponID == CouponId).Select(x => new CouponModel
                {
                    CouponText = x.CouponText,
                    CouponID   = x.CouponID,
                    IsActive   = x.IsActive ?? true,
                }).FirstOrDefault();
                #endregion

                if (model != null)
                {
                    model.EncryptedID = model.CouponID.ToString().ToEnctypt();
                }
                else
                {
                    model = new CouponModel();
                }
            }
            catch (Exception ex)
            {
                EventLogHandler.WriteLog(ex);
            }
            return(model);
        }
Ejemplo n.º 19
0
        public ActionResult CouponUpdate(CouponModel model)
        {
            var response = model.Id == 0
                ? _productService.CouponAdd(model)
                : _productService.CouponEdit(model);

            return(Json(response));
        }
Ejemplo n.º 20
0
        public async Task <ActionResult> Put([FromBody] CouponModel coupon)
        {
            coupon.upd_dt   = DateTime.Now;
            coupon.upd_user = User.Identity.Name;
            await _coupon.Update(coupon);

            return(Ok());
        }
Ejemplo n.º 21
0
 public ActionResult List(string submit, CouponModel m)
 {
     if (submit == "Excel")
     {
         return(new CouponExcelResult(m));
     }
     return(View(m));
 }
Ejemplo n.º 22
0
 public ActionResult List(string submit, CouponModel m)
 {
     if (submit == "Excel")
     {
         return(m.CouponsAsDataTable().ToExcel("Coupons.xlsx"));
     }
     return(View(m));
 }
Ejemplo n.º 23
0
        public ActionResult DeleteCoupon(string param = "")
        {
            CouponModel couponModel = JsonConvert.DeserializeObject <CouponModel>(param);
            long        result      = 0;

            result = _service.CouponRepository.DeleteCouponDetails(couponModel);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public void applyCoupon(CartsModel cartModel, CouponModel coupon)
        {
            List <ProductInCartModel> productsInCart = this.getProductInCart(cartModel.id);

            cartModel = this.calculate(cartModel, productsInCart, coupon);
            _context.Carts.Update(cartModel);
            _context.SaveChanges();
        }
Ejemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual ActionResult Index()
        {
            var model = new CouponModel
            {
                Coupons = GetCoupons()
            };

            return(View("~/Views/Member/Coupon/_Index.cshtml", model));
        }
Ejemplo n.º 26
0
        public ResponseModel SaveCouponHistory(CouponModel objModel)
        {
            var _result = _instance.SaveCouponHistory(objModel);

            return(new ResponseModel()
            {
                Response = _result.Response, Success = _result.Success.Value
            });
        }
Ejemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual ActionResult Index()
        {
            var model = new CouponModel
            {
                Coupons = GetCoupons()
            };

            return(View("Index", model));
        }
Ejemplo n.º 28
0
        public ResponseModel GetCoupon(CouponModel objModel)
        {
            var _result = _instance.GetCoupon(objModel);

            return(new ResponseModel()
            {
                Response = JsonConvert.SerializeObject(_result), Success = true
            });
        }
        public ActionResult Edit(int?id, CouponModel model)
        {
            if (id != null)
            {
                model = model.GetList().FirstOrDefault(m => m.CouponId == id);
            }

            return(View(model));
        }
Ejemplo n.º 30
0
        public static BasketCheckoutEvent ToEvent(
            this BasketCheckoutModel source,
            ICollection <BasketLine> basketLines = null,
            CouponModel coupon = null)
        {
            if (source == null)
            {
                return(null);
            }

            var basketCheckoutEvent = new BasketCheckoutEvent
            {
                Address        = source.Address,
                City           = source.City,
                Country        = source.Country,
                Email          = source.Email,
                BasketId       = source.BasketId,
                BasketTotal    = 0,
                CardExpiration = source.CardExpiration,
                CardName       = source.CardName,
                CardNumber     = source.CardNumber,
                FirstName      = source.FirstName,
                LastName       = source.LastName,
                UserId         = source.UserId,
                ZipCode        = source.ZipCode
            };

            if (basketLines == null || !basketLines.Any())
            {
                return(basketCheckoutEvent);
            }

            basketCheckoutEvent.BasketLines = new List <BasketLineEvent>();

            foreach (var basketLine in basketLines.ToList())
            {
                var basketLineEvent = new BasketLineEvent
                {
                    BasketLineId = basketLine.BasketLineId,
                    Price        = basketLine.Price,
                    TicketAmount = basketLine.TicketAmount
                };

                basketCheckoutEvent.BasketTotal += basketLine.Price * basketLine.TicketAmount;

                basketCheckoutEvent.BasketLines.Add(basketLineEvent);
            }

            if (coupon == null)
            {
                return(basketCheckoutEvent);
            }

            basketCheckoutEvent.BasketTotal -= coupon.Amount;

            return(basketCheckoutEvent);
        }