public ActionResult <AddBookResponseModel> AddToBooked([FromBody] AddToBookListInputModel data) { AddBookResponseModel res = new AddBookResponseModel(); try { BookBL bl = new BookBL(DbContext); var temp = bl.Save(data); string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); //start send Email to Admin var bodyAdmin = bl.BuilBookReceiptToAdmin(data); MailMessage message = new MailMessage(); message.To.Add("*****@*****.**"); message.Body = bodyAdmin; message.Subject = "Booking "; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; PdfConvertEngine pdfEngine = new PdfConvertEngine(); var pdfPath = pdfEngine.ConvertHTMLToPDF(bodyAdmin, AppSettings.PDFPath, temp.BookNo.Replace('/', '_')); Attachment dataPDF = new Attachment(pdfPath); message.Attachments.Add(dataPDF); EmailSenderEngine emailEngine = new EmailSenderEngine(); emailEngine.SendEmail(message, configJSON); dataPDF.Dispose(); //End send Email to admin //start send Email to Media buyer var bodyBuyer = bl.BuilBookReceiptToMediaBuyer(data); UserRepository userRepo = new UserRepository(DbContext); var mediaBuyerInfo = userRepo.FindByID(data.Data[0].UserID).FirstOrDefault(); message = new MailMessage(); message.To.Add(mediaBuyerInfo.UserName); message.Body = bodyBuyer; message.Subject = "Booking "; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; pdfEngine = new PdfConvertEngine(); pdfPath = pdfEngine.ConvertHTMLToPDF(bodyBuyer, AppSettings.PDFPath, temp.BookNo.Replace('/', '_')); dataPDF = new Attachment(pdfPath); message.Attachments.Add(dataPDF); emailEngine = new EmailSenderEngine(); emailEngine.SendEmail(message, configJSON); dataPDF.Dispose(); //End send Email to Media buyer res.data = temp; res.Message = "Success"; res.Response = true; return(Ok(res)); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(BadRequest(res)); } }