public ActionResult Index(ApplicationUser applicationUser)
 {
     try
     {
         applicationUser = DBHelper.ValidateLogin(applicationUser);
         if (applicationUser != null)
         {
             HttpContext.Session["USER"] = applicationUser;
             CompanyConfigurationInfo        configurationSettings = DBHelper.LoadConfigurationSettings(applicationUser.CompanyID.Value);
             Models.CompanyConfigurationInfo config = new Models.CompanyConfigurationInfo()
             {
                 ID                      = configurationSettings.ID,
                 CompanyID               = configurationSettings.CompanyID,
                 CompanyName             = configurationSettings.Company.Company1,
                 ConnectionKey           = configurationSettings.ConnectionKey,
                 DefaultCompanyDetails   = configurationSettings.DefaultCompanyDetails,
                 DefaultEventDescription = configurationSettings.DefaultEventDescription,
                 DefaultPaymentMode      = configurationSettings.DefaultPaymentMode,
                 DefaultPaymentTerms     = configurationSettings.DefaultPaymentTerms,
                 DistanceCalculation     = configurationSettings.DistanceCalculation,
                 EmailPassword           = configurationSettings.EmailPassword,
                 EmailPort               = configurationSettings.EmailPort,
                 EmailSMTP               = configurationSettings.EmailSMTP,
                 EmailUserName           = configurationSettings.EmailUserName,
                 EnforcePassengerCount   = configurationSettings.EnforcePassengerCount,
                 InvoiceEmailTemplate    = configurationSettings.InvoiceEmailTemplate,
                 InvoicePDFPath          = configurationSettings.InvoicePDFPath,
                 MinimumDistance         = configurationSettings.MinimumDistance,
                 ModifiedBy              = configurationSettings.ModifiedBy,
                 ModifiedOn              = configurationSettings.ModifiedOn,
                 PDFPaymentTerms         = configurationSettings.PDFPaymentTerms,
                 QuotationEmailTemplate  = configurationSettings.QuotationEmailTemplate,
                 QuotationMinimumValue   = configurationSettings.QuotationMinimumValue,
                 QuotationPDFPath        = configurationSettings.QuotationPDFPath,
                 QuotationValidityPeriod = configurationSettings.QuotationValidityPeriod,
                 Status                  = configurationSettings.Status
             };
             HttpContext.Session["CONFIGURATION"] = config;
             if (applicationUser.UserRoleID == Convert.ToInt32(UserRoll.Dispatcher))
             {
                 return(RedirectToAction("Index", "Dispatch"));
             }
             else
             {
                 return(RedirectToAction("Index", "BookingQuote"));
             }
         }
         else
         {
             TempData["GlobalMessage"] = commonHelper.SetMessage("User Name or Password is Invalid!!", "E");
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(View());
 }
        public void SendInvoiceConfirmation(BookingQuoteInfoModel bookingQuoteInfoModal, Models.CompanyConfigurationInfo ConfigurationSettings)
        {
            try
            {
                if (bookingQuoteInfoModal.EmailAddress != null && bookingQuoteInfoModal.EmailAddress != string.Empty)
                {
                    MailAddress mailfrom = null;
                    SmtpClient  smtp     = null;
                    if (ConfigurationManager.AppSettings["Gmail"].ToString() == "true")
                    {
                        smtp = new SmtpClient(ConfigurationManager.AppSettings["GmailSMTP"], Convert.ToInt32(ConfigurationManager.AppSettings["GmailSMTPPort"]));
                        //smtp.UseDefaultCredentials = false;
                        smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["GmailUserName"], ConfigurationManager.AppSettings["GmailPassword"]);
                        smtp.EnableSsl   = true;
                        mailfrom         = new MailAddress(ConfigurationManager.AppSettings["GmailUserName"]);
                    }
                    else
                    {
                        smtp             = new SmtpClient(ConfigurationSettings.EmailSMTP, Convert.ToInt32(ConfigurationSettings.EmailPort));
                        smtp.Credentials = new NetworkCredential(ConfigurationSettings.EmailUserName, ConfigurationSettings.EmailPassword);
                        smtp.EnableSsl   = false;
                        mailfrom         = new MailAddress(ConfigurationSettings.EmailUserName);
                    }

                    MailAddress mailto = new MailAddress(bookingQuoteInfoModal.EmailAddress);
                    MailMessage newmsg = new MailMessage(mailfrom, mailto);

                    newmsg.Subject    = ConfigurationManager.AppSettings["InvoiceEmailSubject"].Replace("##InvoiceNumber##", bookingQuoteInfoModal.BookingInfo.AlternateID.ToString());;
                    newmsg.IsBodyHtml = true;
                    newmsg.Body       = GetInvoiceEmailBody(bookingQuoteInfoModal, ConfigurationSettings);

                    //For File Attachment, more file can also be attached
                    Attachment att = new Attachment(ConfigurationManager.AppSettings["InvoicePDF"] + bookingQuoteInfoModal.BookingInfo.InvoiceFileName);
                    newmsg.Attachments.Add(att);

                    smtp.Send(newmsg);
                }
            }
            catch (Exception ex)
            {
                Logging.SendErrorToText(ex);
            }
        }
        public string GetInvoiceEmailBody(BookingQuoteInfoModel bookingQuoteInfoModal, Models.CompanyConfigurationInfo ConfigurationSettings)
        {
            //string body = "<html><body style='color:black; font-size:15px;'><font face='Helvetica, Arial, sans-serif'><div style='padding:30px; margin-top:30px;'><p>Dear ##Username##,</p>Good Day, Thank you for booking with eBus Special Hire.<br>Please find the attachment for the Invoice write/call back to us for any clarification<br><br>Thank you,<br>Ebus Supplies C C<br>33 Judges Avenue,<br>Tel: 011 476 5400<br>Fax: 086 554 2482<br><p></p></div></body></html>";
            string body = ConfigurationSettings.InvoiceEmailTemplate;

            body = body.Replace("##Username##", bookingQuoteInfoModal.FirstName);
            return(body);
        }
예제 #4
0
        public string GenerateQuotationToPDF(BookingQuoteInfoModel bookingQuoteInfo)
        {
            int    count = 0;
            string temp  = "";
            List <BookingVehicleInfoModel> tempVehicles = bookingQuoteInfo.BookingVehicleInfo;

            bookingQuoteInfo.BookingVehicleInfo = new List <BookingVehicleInfoModel>();
            List <BookingVehicleInfoModel> vehicles = tempVehicles.AsEnumerable()
                                                      .Select(row => row)
                                                      .OrderBy(x => x.BusType)
                                                      .ToList();

            for (int i = 0; i < vehicles.Count; i++)
            {
                if (i != 0)
                {
                    if (temp == vehicles[i].BusType)
                    {
                        count = count + 1;
                    }
                    else
                    {
                        bookingQuoteInfo.BookingVehicleInfo.Add(new BookingVehicleInfoModel()
                        {
                            BusType = vehicles[i].BusType, Quantity = count
                        });
                        temp  = vehicles[i].BusType;
                        count = 1;
                    }
                }
                else
                {
                    temp  = vehicles[i].BusType;
                    count = count + 1;
                }
            }
            bookingQuoteInfo.BookingVehicleInfo.Add(new BookingVehicleInfoModel()
            {
                BusType = temp, Quantity = count
            });

            if (bookingQuoteInfo.IsTrailerRequired)
            {
                count = 0;
                temp  = "";
                List <BookingTrailerInfoModel> tempTrailers = bookingQuoteInfo.BookingTrailerInfo;
                bookingQuoteInfo.BookingTrailerInfo = new List <BookingTrailerInfoModel>();
                List <BookingTrailerInfoModel> trailers = tempTrailers.AsEnumerable()
                                                          .Select(row => row)
                                                          .OrderBy(x => x.TrailerType)
                                                          .ToList();
                for (int i = 0; i < trailers.Count; i++)
                {
                    if (i != 0)
                    {
                        if (temp == trailers[i].TrailerType)
                        {
                            count = count + 1;
                        }
                        else
                        {
                            bookingQuoteInfo.BookingTrailerInfo.Add(new BookingTrailerInfoModel()
                            {
                                TrailerType = trailers[i].TrailerType, Quantity = count
                            });
                            temp  = trailers[i].TrailerType;
                            count = 1;
                        }
                    }
                    else
                    {
                        temp  = trailers[i].TrailerType;
                        count = count + 1;
                    }
                }
                bookingQuoteInfo.BookingTrailerInfo.Add(new BookingTrailerInfoModel()
                {
                    TrailerType = temp, Quantity = count
                });
            }

            if (bookingQuoteInfo.CompTelephoneExtension != string.Empty)
            {
                bookingQuoteInfo.CompTelephoneNumber = string.Empty;
                bookingQuoteInfo.CompTelephoneNumber = bookingQuoteInfo.CompTelephoneNumber + bookingQuoteInfo.CompTelephoneExtension;
            }
            string extension = ".pdf";
            string fileName  = ConfigurationSettings.CompanyName + "_Quotation_" + bookingQuoteInfo.AlternateID.ToString() + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + extension;

            try
            {
                Rotativa.ViewAsPdf actionResult = new Rotativa.ViewAsPdf("ExportQuotationToPDF", bookingQuoteInfo);
                byte[]             byteArray    = actionResult.BuildPdf(ControllerContext);
                FileStream         fileStream   = new FileStream(Server.MapPath("~/PDF/" + fileName), FileMode.Create, FileAccess.Write);
                fileStream.Write(byteArray, 0, byteArray.Length);
                fileStream.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }


            bookingQuoteInfo.QuotationFileName = fileName;
            Models.CompanyConfigurationInfo settings = ConfigurationSettings;
            new Task(() =>
            {
                DBHelper.UpdateQuotationFileName(fileName, bookingQuoteInfo.ID, settings.ConnectionKey);
            }).Start();

            try
            {
                if (bookingQuoteInfo.EmailAddress != null && bookingQuoteInfo.EmailAddress != string.Empty)
                {
                    new Task(() =>
                    {
                        EmailHelper.SendQuotationConfirmation(bookingQuoteInfo, settings);
                    }).Start();
                }
            }
            catch (Exception)
            {
                //ignore
            }

            UriBuilder urlBuilder =
                new System.UriBuilder(Request.Url.AbsoluteUri)
            {
                Path  = Url.Content("~/PDF/" + fileName),
                Query = null,
            };
            string url = urlBuilder.ToString();

            return(url);
        }