public BonusDto Resolve(History source, HistoryDto destination, BonusDto destMember, ResolutionContext context) { try { return(_mapper.Map <BonusDto>(_bonusService.FindBonusByIdAsync(source.BonusId).GetAwaiter() .GetResult())); } catch { //Vendor does not finded by Id return(new BonusDto()); } }
public async Task Bonus_FindBonusByIdAsync_Return_BonusDTO() { CreateDefaultBonusServiceInstance(); var idBonus = _fakeBonuseDtos[0].Id; var bonus = await _bonusService.FindBonusByIdAsync(idBonus, default(CancellationToken)); Assert.NotNull(bonus); }
public async Task SendEmailAsync(History history) { var user = await _userService.GetUserAsync(history.CreatorId.ToString()); var bonus = await _bonusService.FindBonusByIdAsync(history.BonusId); var vendor = await _vendorService.GetVendorByIdAsync(bonus.Company.Id); string promoCode = vendor.Name + RandomString(5); var strToUser = String.Format("Hi {0} {1} your order recived. You ordered {2} by {3} company." + " For more information, please call {4} or email {5}." + " Validity period from {6} to {7}." + " Your promo code is {8}", user.FirstName, user.LastName, bonus.Title, bonus.Company.Name, bonus.Phone, vendor.Email, bonus.DateStart, bonus.DateEnd, promoCode); var strToVendor = String.Format("Dear {0}, {1} {2} will come to you with promo. PromoCode is {3}", vendor.Name, user.FirstName, user.LastName, promoCode); MimeMessage messageToUser = new MimeMessage(); messageToUser.From.Add(new MailboxAddress(vendor.Name, vendor.Email)); messageToUser.To.Add(new MailboxAddress(user.Email)); messageToUser.Subject = "Get bonus"; messageToUser.Body = new BodyBuilder() { HtmlBody = String.Format("<div>{0}</div>", strToUser) }.ToMessageBody(); MimeMessage messageToVendor = new MimeMessage(); messageToVendor.From.Add(new MailboxAddress(user.FirstName, user.Email)); messageToVendor.To.Add(new MailboxAddress(vendor.Email)); messageToVendor.Subject = "Get bonus"; messageToVendor.Body = new BodyBuilder() { HtmlBody = String.Format("<div>{0}</div>", strToVendor) }.ToMessageBody(); using (MailKit.Net.Smtp.SmtpClient client = new MailKit.Net.Smtp.SmtpClient()) { client.Connect(_emailSettings.Value.SMTPServer, _emailSettings.Value.SMTPServerPort, true); client.Authenticate(_emailSettings.Value.EmailAddress, _emailSettings.Value.Password); client.Send(messageToUser); client.Send(messageToVendor); client.Disconnect(true); } }
public async Task <ActionResult <ResultDto <IEnumerable <BonusDto> > > > FindBonusByIdAsync([FromRoute] Guid id) { return(Ok(await _BonusService.FindBonusByIdAsync(id))); }