public NewsLetterDto EditNewsletter(NewsLetterDto newsLetterDto, int userId, int tenantId) { var newsletterObj = _NewsletterService.Query(x => x.NewsLetterId == newsLetterDto.NewsLetterId).Select().FirstOrDefault(); if (newsletterObj == null) { throw new NotFoundException(ErrorCodes.ProductNotFound); } newsletterObj.Email = newsLetterDto.Email; //newsletterObj.SeenUser = newsLetterDto.SeenUser; _NewsletterService.Update(newsletterObj); SaveChanges(); return(newsLetterDto); }
public NewsLetterDto CreateNewsletter(NewsLetterDto NewsLetterDto, int userId, int tenantId) { if (GetNewsletter(NewsLetterDto.NewsLetterId, tenantId) != null) { return(EditNewsletter(NewsLetterDto, userId, tenantId)); } var newsletterObj = Mapper.Map <NewsLetter>(NewsLetterDto); newsletterObj.SeenUserId = NewsLetterDto.SeenUserId; newsletterObj.Email = NewsLetterDto.Email; newsletterObj.CreationTime = Strings.CurrentDateTime; newsletterObj.CreatorUserId = userId; _NewsletterService.Insert(newsletterObj); SaveChanges(); return(NewsLetterDto); }
public async Task <bool> GenerateNewsLetter() { try { var initiativeYear = await _unitOfWork.InitiativeYear.GetInitiativeYearByYear(DateTime.Now.Year); var initiativeList = await _unitOfWork.Initiative.GetInitiatives(initiativeYear.Id.ToString()); var reportList = new List <NewsLetterDto>(); foreach (var initiative in initiativeList) { var report = new NewsLetterDto(); var initiativeId = initiative.Id.ToString(); report.InitativeId = initiativeId; report.Initative = initiative.Name; var topContributors = await _unitOfWork.InitiativeMember.GetTopContributors(initiativeId); if (topContributors != null) { report.TopContributors = topContributors; } var upComingReviewCycles = await _unitOfWork.ReviewCycle.GetUpComingReviewCycles(initiativeId); if (upComingReviewCycles != null) { report.UpComingReviewCycles = upComingReviewCycles; } reportList.Add(report); } var model = new NewsLetterViewModel(reportList); const string view = "/Views/Emails/NewsLetter/NewsLetter"; var htmlBody = await _renderer.RenderViewToStringAsync($"{view}Html.cshtml", model); await _azureBusService.SendNewsLetterAsync(htmlBody); return(true); } catch (Exception e) { Console.WriteLine($"error message: {e}"); return(false); } }