Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (DiscountCode.Length != 0)
            {
                hash ^= DiscountCode.GetHashCode();
            }
            if (VoucherCode.Length != 0)
            {
                hash ^= VoucherCode.GetHashCode();
            }
            if (Amount != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Amount);
            }
            if (ItemName.Length != 0)
            {
                hash ^= ItemName.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public long CalculateValue(Guid shoppingCartId, long amount, VoucherCode code, Guid?userId)
        {
            long value = 0;

            value = (amount / 100) * code.Value;
            return(value);
        }
Exemplo n.º 3
0
 public VoucherCreated(Guid id, Guid customerId, VoucherStatus status, Money amount, VoucherCode code, DateTime expirationDate)
 {
     Id = id;
     CustomerId = customerId;
     Status = status;
     Amount = amount;
     Code = code;
     ExpirationDate = expirationDate;
 }
Exemplo n.º 4
0
 public VoucherCreated(Guid id, Guid customerId, VoucherStatus status, Money amount, VoucherCode code, DateTime expirationDate)
 {
     Id             = id;
     CustomerId     = customerId;
     Status         = status;
     Amount         = amount;
     Code           = code;
     ExpirationDate = expirationDate;
 }
Exemplo n.º 5
0
 public async Task <ActionResult> Put(int id, [FromBody] VoucherCode voucher)
 {
     if (id != voucher?.Id)
     {
         return(new StatusCodeResult(400));
     }
     return(await _voucherCodeBusinessComponent.Update(voucher) ?
            new StatusCodeResult(204) : new StatusCodeResult(404));
 }
Exemplo n.º 6
0
        public static bool IsValidCode(string voucherCode, out VoucherCode code)
        {
            using (var db = new CoreEcommerceDbContext())
            {
                code = db.VoucherCodes.SingleOrDefault(
                    i => i.Code.Equals(voucherCode, StringComparison.OrdinalIgnoreCase));
                if (code == null)
                {
                    return(true);
                }

                return(!code.Applied);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generates a voucher code.
        /// Only admins are allowed to use this functionality
        /// </summary>
        /// <returns></returns>
        public async Task <VoucherCode> GenerateVoucherCode(VoucherStatus status, short numberOfSeats, long scheduleId)
        {
            var voucherCode = new VoucherCode()
            {
                Code = _randomCodeGenerator.Next(),
                NumberOfFreeSeats = numberOfSeats,
                ScheduleId        = scheduleId,
                Status            = status
            };

            await _voucherCodeRepository.Add(voucherCode);

            await _voucherCodeRepository.Commit();

            return(voucherCode);
        }
        private static void CreateVourcherTarget(CampaignItem campaignItem)
        {
            var voucherTarget = new VoucherTarget();

            voucherTarget.EnabledForDisplay = false;
            voucherTarget.EnabledForApply   = true;
            voucherTarget.CampaignItem      = campaignItem;
            var voucherCode = new VoucherCode()
            {
                Code          = "demo",
                MaxUses       = 10000,
                NumberUsed    = 0,
                VoucherTarget = voucherTarget
            };

            voucherTarget.VoucherCodes.Add(voucherCode);
            voucherTarget.Name = "target";
            voucherTarget.Save();
        }
Exemplo n.º 9
0
        public async Task <bool> Update(VoucherCode voucher)
        {
            var dbVoucher = await GetById(voucher.Id);

            if (voucher == null)
            {
                return(false);
            }
            if (voucher.Code != dbVoucher.Code)
            {
                throw new InvalidOperationException("Can't update voucher because vouchercode is not a db match");
            }

            dbVoucher.NumberOfFreeSeats = voucher.NumberOfFreeSeats;
            dbVoucher.ScheduleId        = voucher.ScheduleId;
            dbVoucher.Status            = voucher.Status;
            await _voucherCodeRepository.Commit();

            return(true);
        }
Exemplo n.º 10
0
 public long CalculateValue(Guid shoppingCartId, long amount, VoucherCode code, Guid?userId)
 {
     return(code.Value);
 }
Exemplo n.º 11
0
        public async Task <ActionResult> Post([FromBody] VoucherCode voucherCode)
        {
            var voucher = await _voucherCodeBusinessComponent.GenerateVoucherCode(voucherCode.Status, voucherCode.NumberOfFreeSeats, voucherCode.ScheduleId);

            return(Json(voucher));
        }
Exemplo n.º 12
0
 public Voucher GetVaucherByCode(string code)
 {
     var voucherCode = new VoucherCode(code);
     return _session.Query<Voucher>().SingleOrDefault(v => v.Code == voucherCode);
 }
Exemplo n.º 13
0
        protected override void SetMemento(IMemento memento)
        {
            var voucherMemento = (VoucherMemento)memento;

            Id = voucherMemento.Id;
            Version = voucherMemento.Version;
            CustomerId = voucherMemento.CustomerId;
            Code = new VoucherCode(voucherMemento.Code);
            Status = (VoucherStatus)voucherMemento.Status;
            ExpirationDate = voucherMemento.ExpirationDate;
            Amount = new Money(voucherMemento.Amount);
        }
Exemplo n.º 14
0
        public Voucher GetVaucherByCode(string code)
        {
            var voucherCode = new VoucherCode(code);

            return(_session.Query <Voucher>().SingleOrDefault(v => v.Code == voucherCode));
        }