public ActionResult <ApprovalBookResponseModel> ApprovalBooked([FromBody] ApprovalBookInputModel data) { ApprovalBookResponseModel res = new ApprovalBookResponseModel(); try { BookBL bl = new BookBL(DbContext); var temp = bl.ApprovalBook(data); string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); res.data = temp; res.Response = true; res.Message = temp.Message; res.TotalPages = 1; //Send email to Media Buyer var bodyBuyer = bl.BuilBookEmailApprovalToMediaBuyer(data, temp.Message); UserRepository userRepo = new UserRepository(DbContext); var mediaBuyerInfo = userRepo.FindByID(data.UserID).FirstOrDefault(); MailMessage message = new MailMessage(); message.To.Add(mediaBuyerInfo.UserName); message.Body = bodyBuyer; message.Subject = "Booking "; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; PdfConvertEngine pdfEngine = new PdfConvertEngine(); var pdfPath = pdfEngine.ConvertHTMLToPDF(bodyBuyer, AppSettings.PDFPath, "INV_01_123"); Attachment dataPDF = new Attachment(pdfPath); dataPDF = new Attachment(pdfPath); message.Attachments.Add(dataPDF); EmailSenderEngine emailEngine = new EmailSenderEngine(); emailEngine.SendEmail(message, configJSON); dataPDF.Dispose(); //end send email to media buyer return(Ok(res)); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(BadRequest(res)); } }
public ActionResult <PurchaseResponseModel> TesEmailInvoice() { PurchaseResponseModel res = new PurchaseResponseModel(); try { PurchaseOutputModel temp = new PurchaseOutputModel(); ReportBL invoice = new ReportBL(DbContext); var body = invoice.BuildInvoice(temp); MailMessage message = new MailMessage(); message.To.Add("*****@*****.**"); message.Body = body; message.Subject = "Pembelian 7061BTJW Telah Selesai"; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; PdfConvertEngine pdfEngine = new PdfConvertEngine(); var pdfPath = pdfEngine.ConvertHTMLToPDF(body, AppSettings.PDFPath, "INV_01_123"); Attachment dataPDF = new Attachment(pdfPath); message.Attachments.Add(dataPDF); EmailSenderEngine emailEngine = new EmailSenderEngine(); string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); emailEngine.SendEmail(message, configJSON); dataPDF.Dispose(); return(res); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(res); } }
public ActionResult <ForgotPasswordResponseModel> ForgotPassword([FromBody] ForgotPasswordMobileInputModel data) { try { ForgotPasswordBL forPasswordBL = new ForgotPasswordBL(DbContext); var url = AppSettings.URLForgotPassword; var result = forPasswordBL.SendURL(data.UserName, url); if (result.Response) { var locationHtml = AppSettings.TemplatePath + "EmailResetPassword.html"; string content = System.IO.File.ReadAllText(locationHtml); content = content.Replace("$BASE_URL", AppSettings.BaseURL); content = content.Replace("$ForgetPassword_URL", AppSettings.BaseURL + AppSettings.URLForgotPassword + result.data.ID); MailMessage message = new MailMessage(); message.To.Add(result.data.UserName); message.Body = content; message.Subject = "Forgot Password"; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; EmailSenderEngine emailEngine = new EmailSenderEngine(); string configOnJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); emailEngine.SendEmail(message, configOnJSON); } return(result); } catch (Exception ex) { ForgotPasswordResponseModel logres = new ForgotPasswordResponseModel(); logres.Message = ex.Message; logres.Response = false; return(logres); } }
public ActionResult <PurchaseResponseModel> ProcessToPurchase([FromBody] PurchaseInputModel data) { PurchaseResponseModel res = new PurchaseResponseModel(); try { PurchaseBL bl = new PurchaseBL(DbContext); var temp = bl.Process(data); res.data = temp; res.Message = "Success"; res.Response = true; if (temp.IDTransaction != Guid.Empty) { ReportBL invoice = new ReportBL(DbContext); var body = invoice.BuildInvoice(temp); MailMessage message = new MailMessage(); message.To.Add("*****@*****.**"); message.Body = body; message.Subject = "Pembelian 7061BTJW Telah Selesai"; message.From = new MailAddress(AppSettings.EmailConfig.FromAddress); message.IsBodyHtml = true; EmailSenderEngine emailEngine = new EmailSenderEngine(); string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); emailEngine.SendEmail(message, configJSON); } return(res); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(res); } }
public ActionResult <AddItemToCurrentBookResponseModel> AddItemToCurrentBook([FromBody] AddItemToCurrentBookListInputModel data) { AddItemToCurrentBookResponseModel res = new AddItemToCurrentBookResponseModel(); try { BookBL bl = new BookBL(DbContext); var temp = bl.ChangeItemCurrentBook(data); string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig); //start send Email to Admin var bodyAdmin = bl.BuilBookChangeReceiptToAdmin(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.BuilBookChangeReceiptToMediaBuyer(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)); } }