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); }
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; }
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)); }
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); } }
/// <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(); }
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); }
public long CalculateValue(Guid shoppingCartId, long amount, VoucherCode code, Guid?userId) { return(code.Value); }
public async Task <ActionResult> Post([FromBody] VoucherCode voucherCode) { var voucher = await _voucherCodeBusinessComponent.GenerateVoucherCode(voucherCode.Status, voucherCode.NumberOfFreeSeats, voucherCode.ScheduleId); return(Json(voucher)); }
public Voucher GetVaucherByCode(string code) { var voucherCode = new VoucherCode(code); return _session.Query<Voucher>().SingleOrDefault(v => v.Code == voucherCode); }
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); }
public Voucher GetVaucherByCode(string code) { var voucherCode = new VoucherCode(code); return(_session.Query <Voucher>().SingleOrDefault(v => v.Code == voucherCode)); }