Exemple #1
0
        public async Task <IActionResult> CreateGift([FromBody] GiftVoucherPostBody vouchers)
        {
            var giftVouchers = new List <GiftVoucher>();

            foreach (var voucher in vouchers.GiftVouchers)
            {
                voucher.Code = GenerateVoucherCode();
                giftVouchers.Add(await _voucherRepository.Create(voucher).ConfigureAwait(false));
            }

            return(Ok(string.Join(", ", giftVouchers.Select(g => $"£{g.Value} Voucher (Code: {g.Code})"))));
        }
        public async Task <ActionResult <Voucher> > Create(Voucher entity)
        {
            Voucher entityCreated = await _repo.Create(entity);

            if (entityCreated != null)
            {
                return(entityCreated);
            }
            else
            {
                return(StatusCode(400, new { result = Messages.MESSAGE_002 }));
            }
        }
        public async Task <IActionResult> CreateVoucher(VoucherCreationDto dto)
        {
            var newVoucher = new VoucherCreationDto
            {
                Number   = dto.Number,
                Date     = dto.Date,
                SubTotal = dto.SubTotal,
                Discount = dto.Discount,
                Total    = dto.Total,
                WayToPay = dto.WayToPay,
                UserId   = dto.UserId
            };

            await _voucherRepository.Create(newVoucher);

            return(Ok(dto));
        }
Exemple #4
0
        public bool Create(VoucherCreateRequest entity)
        {
            string   description       = entity.Description;
            int      quantity          = entity.Quantity;
            int      available         = quantity;
            string   code              = entity.Code;
            DateTime beginDate         = entity.BeginDate;
            DateTime expiredDate       = entity.ExpiredDate;
            int      maxDiscount       = entity.MaxDiscountAmount;
            int      minRequiredAmount = entity.MinRequiredAmount;
            int      percentDiscount   = entity.PercentDiscount;
            int      proId             = entity.PromotionId;

            if (!util.ValidRangeLengthInput(description, 1, 250) ||
                !util.ValidRangeLengthInput(code, 1, 20) ||
                beginDate.CompareTo(expiredDate) == 1 ||
                quantity < 0 ||
                percentDiscount <= 0 || maxDiscount <= 0 || minRequiredAmount <= 0
                )
            {
                return(false);
            }

            Voucher existed = _vouRepo.GetAll().FirstOrDefault(e => e.Code.Trim().ToLower().Equals(code.Trim().ToLower()));

            if (existed != null)
            {
                return(false);
            }
            Voucher newEntity = new Voucher();

            newEntity.Description       = description;
            newEntity.Quantity          = quantity;
            newEntity.Available         = available;
            newEntity.Code              = code;
            newEntity.BeginDate         = beginDate;
            newEntity.ExpiredDate       = expiredDate;
            newEntity.MinRequiredAmount = minRequiredAmount;
            newEntity.MaxDiscountAmount = maxDiscount;
            newEntity.PercentDiscount   = percentDiscount;
            newEntity.PromotionId       = proId;
            return(_vouRepo.Create(newEntity));
        }