Last active
December 19, 2019 15:25
-
-
Save mzekrallah/67a7c8abaedb0ffaddfa48340b779e66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void InsertUniquePromotionForNormalAndDiscountedConsults(int count) | |
{ | |
List<Promotion> promotions = new List<Promotion>(count); | |
IAppSettings appSettings = new AppSettings(); | |
string connectionString = appSettings.GetString("connectionString"); | |
var dbFactory = new OrmLiteConnectionFactory(connectionString, ServiceStack.OrmLite.MySqlDialect.Provider) | |
{ | |
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current) | |
}; | |
//using (var captured = new CaptureSqlFilter()) | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
string code = GenerateRandomCode(5); | |
Promotion normalProdutPromo = new Promotion() | |
{ | |
Title = "100% Off One Time Unique promo", | |
Description = "100% Off One Time Unique promo", | |
DiscountPercentage = 1, | |
Enabled = true, | |
StartDate = DateTime.UtcNow, | |
EndDate = new DateTime(2018, 6, 1), | |
MaxUsagePerCoupon = 1, | |
MaxUsagePerUser = 1, | |
RedeemCount = 0, | |
Code = code, | |
Created = DateTime.UtcNow, | |
Modified = DateTime.UtcNow | |
}; | |
normalProdutPromo.ProductId = 1; | |
promotions.Add(normalProdutPromo); | |
Promotion discountedProductPromo = normalProdutPromo.CreateCopy<Promotion>(); | |
discountedProductPromo.ProductId = 7; | |
promotions.Add(discountedProductPromo); | |
} | |
using (var Db = dbFactory.Open()) | |
{ | |
Db.InsertAll<Promotion>(promotions); | |
} | |
} | |
} | |
public static string GenerateRandomCode(int length) | |
{ | |
var chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
//var chars = "135265093ABDRTZ0156789"; | |
var result = new string( | |
Enumerable.Repeat(chars, length) | |
.Select(s => s[random.Next(s.Length)]) | |
.ToArray()); | |
return result; | |
} | |
======================================================================================================================== | |
GenerateRandomConsultationVoucherPromoCodes(100, new PromotionVoucherCodeDto() | |
{ | |
Title = "Al-Ridaa2 Al3arabi 2018 - 1 Consult Voucher", | |
Description = "Paid cash 63 SAR for 1 consultation", | |
ValidFrom = new DateTime(2018, 4, 24, 0, 0, 0, 0, DateTimeKind.Utc), | |
ValidTo = new DateTime(2018, 07, 31, 23, 59, 59, 0, DateTimeKind.Utc), | |
MaxUsagePerCoupoun = 1, | |
MaxUsagePerUser = 1, | |
DiscountPercentage = 1, | |
CodePrefix = "A6D3R" | |
}); | |
public static void GenerateRandomConsultationVoucherPromoCodes(int quantiy, PromotionVoucherCodeDto promoCodeDetails) | |
{ | |
List<Promotion> promotions = new List<Promotion>(quantiy); | |
IAppSettings appSettings = new AppSettings(); | |
string connectionString = appSettings.GetString("connectionString"); | |
var dbFactory = new OrmLiteConnectionFactory(connectionString, ServiceStack.OrmLite.MySqlDialect.Provider) | |
{ | |
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current) | |
}; | |
//using (var captured = new CaptureSqlFilter()) | |
{ | |
for (int i = 0; i < quantiy; i++) | |
{ | |
string code = promoCodeDetails.CodePrefix + GenerateRandomCode(3); | |
Promotion normalProdutPromo = new Promotion() | |
{ | |
Title = promoCodeDetails.Title, | |
Description = promoCodeDetails.Description, | |
DiscountPercentage = promoCodeDetails.DiscountPercentage, | |
Enabled = true, | |
Code = code, | |
StartDate = promoCodeDetails.ValidFrom, | |
EndDate = promoCodeDetails.ValidTo, | |
MaxUsagePerCoupon = promoCodeDetails.MaxUsagePerCoupoun, | |
MaxUsagePerUser = promoCodeDetails.MaxUsagePerUser, | |
RedeemCount = 0, | |
Created = DateTime.UtcNow, | |
Modified = DateTime.UtcNow | |
}; | |
normalProdutPromo.ProductId = 1; | |
promotions.Add(normalProdutPromo); | |
Promotion discountedProductPromo = normalProdutPromo.CreateCopy<Promotion>(); | |
discountedProductPromo.ProductId = 7; | |
promotions.Add(discountedProductPromo); | |
} | |
using (var Db = dbFactory.Open()) | |
{ | |
Db.InsertAll<Promotion>(promotions); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment