コード例 #1
0
        public IActionResult GenerateCode(CreatePrivatePromotionCode model)
        {
            var success       = false;
            var newCodes      = Enumerable.Range(0, model.NumOfCode).Select(_ => GenerateCode(CodeLength, model.CodePrefix, model.CodeSuffix)).ToList();
            var existingCodes = _privatePromotionRepository.AllCode.Select(v => v.Code).Where(v => newCodes.Contains(v)).ToList();

            if (existingCodes.Count == 0)
            {
                try
                {
                    foreach (var code in newCodes)
                    {
                        var ppCode = new PrivatePromotionCode
                        {
                            Code               = code,
                            CodeComment        = model.CodeComment,
                            CreatedDate        = DateTime.Now,
                            MaxUseCode         = model.MaxUseCode,
                            IsInfinityUse      = model.IsInfinityUse,
                            StartDate          = model.StartDate,
                            EndDate            = model.EndDate,
                            IsInfinityTime     = model.IsInfinityTime,
                            PrivatePromotionId = model.PrivatePromotionId,
                            Status             = true
                        };
                        _privatePromotionRepository.AddPrivatePromotionCode(ppCode);
                    }
                    success = true;
                }
                catch
                { }
            }

            return(Json(new { success }));
        }
コード例 #2
0
        public async Task <string> PostPromotionCode(PrivatePromotionCodeApiModel.Request promo)
        {
            PrivatePromotionCode privatePromotionCode = new PrivatePromotionCode
            {
                privatePromotionCodeId     = new Guid(),
                privatePromotionCodeString = promo.privatePromotionCodeString,
                startDate      = DateTime.Now,
                CustomerId     = new Guid(promo.CustomerId),
                printingShopId = new Guid(promo.printingShopId),
                isExpired      = false,
                isUsed         = false
            };

            await applicationDbContext.privatePromotionCodes.AddAsync(privatePromotionCode);

            await applicationDbContext.SaveChangesAsync();

            return("success");
        }
コード例 #3
0
 public IActionResult EditCode(int id, PrivatePromotionCode privatePromotionCode)
 {
     try
     {
         _privatePromotionRepository.UpdateCode(privatePromotionCode);
         var code = _privatePromotionRepository.GetPrivatePromotionCodeById(privatePromotionCode.Id);
         return(Json(new {
             success = true,
             codeId = code.Id,
             codeComment = code.CodeComment,
             codeStatus = code.Status,
             codeUse = code.IsInfinityUse ? $"{code.CurrentUseCode} / Không giới hạn" : $"{code.CurrentUseCode} / {code.MaxUseCode}",
             codeTime = code.IsInfinityTime ? "Không giới hạn" : code.StartDate?.ToString("dd/MM/yyyy") + " - " + code.EndDate?.ToString("dd/MM/yyyy")
         }));
     }
     catch
     {
         return(Json(new { success = false }));
     }
 }
コード例 #4
0
 public void UpdateCode(PrivatePromotionCode privatePromotionCode)
 {
     _appDbContext.Entry(privatePromotionCode).State = EntityState.Modified;
     _appDbContext.Update(privatePromotionCode);
     _appDbContext.SaveChanges();
 }
コード例 #5
0
 public void AddPrivatePromotionCode(PrivatePromotionCode privatePromotionCode)
 {
     _appDbContext.PrivatePromotionCodes.Add(privatePromotionCode);
     _appDbContext.SaveChanges();
 }