public IActionResult CreateCampaign([FromBody] CreateCampaignRequest request) { if (request.NumberOfCodes >= 1 && request.NumberOfCodes <= 3000) { var sql = new SQL(connectionString: _config.GetConnectionString("Storage")); var codeReader = new CodeReader(fileUrl: _config.GetSection("FileUrls")["SeedBlobUrl"]); var campaign = new Campaign() { Name = request.Name, Size = request.NumberOfCodes }; // Get the last offset position var prevAndNextOffset = sql.UpdateOffset(campaign.Size); // Read from the file var codes = codeReader.GenerateCodesFromFile(prevAndNextOffset); // Create the campaign and insert the codes sql.CreateCampaign(campaign, codes); return(Ok(campaign)); } return(BadRequest()); }
public IActionResult CreateCampaign([FromBody] CreateCampaignRequest request) { if (request.campaignSize >= 1 && request.campaignSize <= 30000) { var campaign = new Campaign() { CampaignName = request.campaignName, CampaignSize = request.campaignSize }; var cloudPath = new CloudPath(_config.GetSection("SeedBlobUrl")["BlobUrl"]); var sql = new SQL(_config.GetConnectionString("SQLConnnection")); var offsetUpdate = sql.UpdateOffset(campaign.CampaignSize); var listOfCodes = cloudPath.GenerateCodesFromCloudFile(offsetUpdate); sql.CreateCampaign(listOfCodes, campaign); return(Ok(campaign)); } return(BadRequest()); }
public IActionResult CreateBatch([FromBody] CreateCampaignRequest request) { if (request.CodesNumber >= 1 && request.CodesNumber <= 3000) { var sql = new SQL(connectionString: _config.GetConnectionString("Storage")); var file = new CloudReader(filePath: _config.GetSection("File")["SeedBlobUrl"]); var promotion = new Promotion() { Name = request.Name, BatchSize = request.CodesNumber }; var firstAndLastOffset = sql.UpdateOffset(promotion.BatchSize); var codes = file.GenerateCodes(firstAndLastOffset); sql.CreateBatch(promotion, codes); return(Ok(promotion)); } return(BadRequest()); }