Example #1
0
        public override async Task <ExecutionStatusResponse> CreatePromo(PromoCreateRequest request, ServerCallContext context)
        {
            var toSaveCode = new PromoCode()
            {
                Code           = PromoGenerator.GenerateCode(),
                Title          = request.Title,
                ExpirationDate = Convert.ToDateTime(request.ExpirationDate),
                Discount       = request.Discount
            };

            var res = new ExecutionStatusResponse
            {
                Status = false
            };

            try
            {
                await _repository.CreateAsync(toSaveCode);

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

            return(res);
        }
Example #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);
        }
 private static IEnumerable <PromoCode> GetOpeningPromocodesAsync()
 {
     return(new List <PromoCode>()
     {
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         },
         new PromoCode()
         {
             Code = PromoGenerator.GenerateCode(),
             Title = "EShop Opening",
             ExpirationDate = DateTime.Now.AddDays(15),
             Discount = 0.3
         }
     });
 }