public async Task <bool> GeneratePromoCodes(PromoGenReqDTO genRequest)
        {
            var requestToGen = new GeneratePromoRequest
            {
                Quantity       = genRequest.Quantity,
                Title          = genRequest.Title,
                ExpirationDate = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(genRequest.ExpirationDate),
                Discount       = genRequest.Discount
            };

            var result = await _discountService.GeneratePromoCodesAsync(requestToGen);

            return(result.Status);
        }
Exemplo n.º 2
0
        public override async Task <ExecutionStatusResponse> GeneratePromoCodes(GeneratePromoRequest request, ServerCallContext context)
        {
            List <PromoCode> promoCodesToSave = new List <PromoCode>();

            var genResult = new ExecutionStatusResponse()
            {
                Status = false
            };

            try
            {
                for (int i = 0; i < request.Quantity; i++)
                {
                    PromoCode pc = new PromoCode()
                    {
                        Code           = PromoGenerator.GenerateCode(),
                        Title          = request.Title,
                        ExpirationDate = request.ExpirationDate.ToDateTime(),
                        Discount       = request.Discount
                    };

                    promoCodesToSave.Add(pc);
                }

                await _repository.CreateManyAsync(promoCodesToSave);

                genResult.Status = true;
                return(genResult);
            }
            catch (Exception e)
            {
                _logger.LogError($"[PROMO-GENERATION]<>Some errors occured: {e.Message}");
            }

            return(genResult);
        }