public async Task <IActionResult> Details(int claimId) { string previousPage = Request.Headers["Referer"].ToString(); if (previousPage.Contains("Claim")) { previousPage = "Claim"; } else { previousPage = "Recommendation"; } //Claim details ClaimWithPromotionAndShopInfo cwpasi = await _claimService.RetrieveClaimWithPromotionAndShopInfoByClaimIdAsync(claimId); //QRCode string txtQrCode = $"ClaimId_{claimId}_ShopProfileId_{cwpasi.PromotionDto.ShopProfileId}_PromotionId_{cwpasi.PromotionDto.PromotionId}"; QRCodeGenerator qrCodeGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(txtQrCode, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); byte[] qrBytes = await BitmapToBytes(qrCodeImage); //Viewmodel ClaimViewModel claimViewModel = new ClaimViewModel { ClaimExtraInfo = cwpasi, QrBtyes = qrBytes, PreviousPage = previousPage }; return(View(claimViewModel)); }
public async Task <ClaimWithPromotionAndShopInfo> RetrieveClaimWithPromotionAndShopInfoByClaimIdAsync(int claimId) { //Get claim var claim = await RetrieveAsync(claimId); //Get promotion string apiUrl = URLConfig.Promotion.RetrievePromotionAPI(_apiUrls.PromotionAPI_Retrieve); apiUrl += "?promotionId=" + claim.PromotionId; var response = await _httpClient.GetStringAsync(apiUrl); var promotion = !string.IsNullOrEmpty(response) ? JsonConvert.DeserializeObject <Promotion>(response) : null; //Get shopProfile string apiUrl2 = URLConfig.ShopProfile.ShopProfileAPI(_apiUrls.ShopProfileAPI_Retrieve); apiUrl2 += "?shopProfileId=" + promotion.ShopProfileId; var response2 = await _httpClient.GetStringAsync(apiUrl2); var shopProfile = !string.IsNullOrEmpty(response2) ? JsonConvert.DeserializeObject <ShopProfile>(response2) : null; //Combine all into ClaimWithPromotionAndShopInfo var claimWithPromotionAndShopInfo = new ClaimWithPromotionAndShopInfo { ClaimDto = claim, PromotionDto = promotion, ShopProfileDto = shopProfile }; return(claimWithPromotionAndShopInfo); }
public async Task <IEnumerable <ClaimWithPromotionAndShopInfo> > RetrieveClaimsWithPromotionAndShopInfoByCustomerProfileIdAsync(int customerProfileId) { //Get list of claims string apiUrl = URLConfig.Claim.ClaimAPI(_apiUrls.ClaimAPI_RetrieveByCustomerProfileId); apiUrl += "?customerProfileId=" + customerProfileId; var response = await _httpClient.GetStringAsync(apiUrl); var claims = !string.IsNullOrEmpty(response) ? JsonConvert.DeserializeObject <IEnumerable <Claim> >(response) : null; //Get list of promotions string apiUrl2 = URLConfig.Promotion.RetrievePromotionsByPromotionIdsAPI(_apiUrls.PromotionAPI_RetrievePromotionsByPromotionIds); var payLoad2 = new StringContent(JsonConvert.SerializeObject(claims.Select(c => c.PromotionId)), Encoding.UTF8, "application/json"); var response2 = await _httpClient.PostAsync(apiUrl2, payLoad2); var promotions = await response2.Content.ReadAsAsync <IEnumerable <Promotion> >(); //Get list of shopProfiles string apiUrl3 = URLConfig.ShopProfile.ShopProfileAPI(_apiUrls.ShopProfileAPI_RetrieveShopProfilesByShopProfileIds); var payLoad3 = new StringContent(JsonConvert.SerializeObject(promotions.Select(p => p.ShopProfileId)), Encoding.UTF8, "application/json"); var response3 = await _httpClient.PostAsync(apiUrl3, payLoad3); var shopProfiles = await response3.Content.ReadAsAsync <IEnumerable <ShopProfile> >(); //Combine all into ClaimWithPromotionAndShopInfo var claimWithPromotionAndShopInfos = claims.Select(c => { var cwpasi = new ClaimWithPromotionAndShopInfo(); cwpasi.ClaimDto = c; cwpasi.PromotionDto = promotions.FirstOrDefault(p => p.PromotionId == c.PromotionId); cwpasi.ShopProfileDto = shopProfiles.FirstOrDefault(s => s.ShopProfileId == cwpasi.PromotionDto.ShopProfileId); return(cwpasi); }); return(claimWithPromotionAndShopInfos); }
public async Task <IActionResult> Claim(int promotionId) { string userName = HttpContext.Session.GetString("username"); var customerProfile = (await _customerProfileService.CustomerProfile(userName)); var customerProfileId = customerProfile.CustomerProfileId; var customerEmailAddr = customerProfile.CustomerEmail; Claim claim = new Claim { PromotionId = promotionId, CustomerProfileId = customerProfileId }; var result = await _claimService.ClaimAsync(claim); if (result != null) { //Claim details int claimId = result.ClaimId; ClaimWithPromotionAndShopInfo cwpasi = await _claimService.RetrieveClaimWithPromotionAndShopInfoByClaimIdAsync(claimId); //QRCode string txtQrCode = $"ClaimId_{claimId}_ShopProfileId_{cwpasi.PromotionDto.ShopProfileId}_PromotionId_{cwpasi.PromotionDto.PromotionId}"; QRCodeGenerator qrCodeGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(txtQrCode, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); byte[] qrBytes = await BitmapToBytes(qrCodeImage); string qrCodeString = Convert.ToBase64String(qrBytes); /*mailkit*/ var emailAddr = new Common.DBTableModelsService.EmailService.EmailAddress { Address = customerEmailAddr, Name = userName }; var emailMessage = new Common.DBTableModelsService.EmailService.EmailMessage { FromAddresses = new List <Common.DBTableModelsService.EmailService.EmailAddress> { emailAddr }, ToAddresses = new List <Common.DBTableModelsService.EmailService.EmailAddress> { emailAddr }, Content = $@" <div style=""margin - left:0; ""> <img src=""data:image/png;base64,{qrCodeString}"" height=""300"" width=""300"" /> </div> <div> <br /><b>Shop:</b>{cwpasi.ShopProfileDto.ShopName} <br /><b>Promotion Title:</b>{cwpasi.PromotionDto.Header} <br /><b>Promotion Description:</b>{cwpasi.PromotionDto.Description} <br /><b>Promotion Start Date:</b>{cwpasi.PromotionDto.StartDate.ToString("yyyy-MM-dd")} <br /><b>Promotion End Date:</b>{cwpasi.PromotionDto.EndDate.ToString("yyyy-MM-dd")} </div> ", Subject = "PromotionsSG Claim Voucher" }; var emailResult = await _notificationService.SendEmailAsync(emailMessage); return(emailResult ? new JsonResult(result) : new JsonResult(null)); } return(new JsonResult(null)); }