private void SeedDb()
        {
            this.TruncatePostReportsTable();
            this.TruncateReplyReportsTable();
            this.TruncateUsersTable();
            this.TruncateQuoteReportsTable();

            var user = new ForumUser {
                Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1
            };

            this.dbService.DbContext.Users.Add(user);
            this.dbService.DbContext.SaveChanges();

            var replyReport = new ReplyReport {
                Author = user, AuthorId = user.Id
            };
            var postReport = new PostReport {
                Author = user, AuthorId = user.Id
            };
            var quoteReport = new QuoteReport {
                Author = user, AuthorId = user.Id
            };

            this.dbService.DbContext.ReplyReports.Add(replyReport);
            this.dbService.DbContext.PostReports.Add(postReport);
            this.dbService.DbContext.QuoteReports.Add(quoteReport);
            this.dbService.DbContext.SaveChanges();
        }
Ejemplo n.º 2
0
 public IHttpActionResult SendCustomerQuoteMail(FrayteQuotationEmailMail CustomerEmailDetail)
 {
     try
     {
         FrayteQuotationResult result = new FrayteQuotationResult();
         var fileResult = new QuoteReport().GetQuotation(CustomerEmailDetail.QuotationDetail.QuotationShipmentId, CustomerEmailDetail.Name, CustomerEmailDetail.QuotationDetail.QuotationFromAddress.PostCode, CustomerEmailDetail.QuotationDetail.QuotationToAddress.PostCode, CustomerEmailDetail.LoginUserId);
         var ratecard   = new CustomerBaseRateReport().CustomerQuoteRateCard(CustomerEmailDetail.QuotationDetail.QuotationShipmentId);
         result = new ShipmentEmailRepository().SendCustomerQuoteMail(CustomerEmailDetail, fileResult, ratecard);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return(BadRequest());
     }
 }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Quote(int id)
        {
            try {
                var order = await _repo.Get(id);

                if (order == null)
                {
                    return(NotFound());
                }

                var report = new QuoteReport(order) as SectionReport;
                report.Run();
                return(Ok(report));
            } catch (Exception ex) {
                return(Ok(ex));
            }
        }
Ejemplo n.º 4
0
 public IHttpActionResult GenerateQuotationShipmentPdf(FrayteQuotationShipment quotationDetail)
 {
     try
     {
         FrayteManifestName fileResult = new FrayteManifestName();
         if (quotationDetail.QuotationShipmentId > 0)
         {
             fileResult = new QuoteReport().GetQuotation(quotationDetail.QuotationShipmentId, quotationDetail.CustomerName, quotationDetail.QuotationFromAddress.PostCode, quotationDetail.QuotationToAddress.PostCode, quotationDetail.CreatedBy);
             return(Ok(fileResult));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return(BadRequest());
     }
 }
Ejemplo n.º 5
0
 public IHttpActionResult SendQuotationMail(FrayteQuotationEmailMail quotationEmailDetail)
 {
     try
     {
         FrayteQuotationResult result = new FrayteQuotationResult();
         if (quotationEmailDetail.QuotationDetail.QuotationShipmentId > 0)
         {
             //Step 1: Get Surcharge Detail According Choose Service
             var fileResult = new QuoteReport().GetQuotation(quotationEmailDetail.QuotationDetail.QuotationShipmentId, quotationEmailDetail.Name, quotationEmailDetail.QuotationDetail.QuotationFromAddress.PostCode, quotationEmailDetail.QuotationDetail.QuotationToAddress.PostCode, quotationEmailDetail.LoginUserId);
             var ratecard   = new CustomerBaseRateReport().CustomerQuoteRateCard(quotationEmailDetail.QuotationDetail.QuotationShipmentId);
             result = new ShipmentEmailRepository().SendQuotationMail(quotationEmailDetail, fileResult, ratecard);
             return(Ok(result));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return(BadRequest());
     }
 }
Ejemplo n.º 6
0
        public async Task <IHttpActionResult> EmailQuote(EmailInputModel model)
        {
            var fromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
            var user        = Request.GetOwinContext().Request.User;

            var order = await _repo.Get(model.OrderId);

            var report = new QuoteReport(order) as SectionReport;

            report.Run();
            var memStream = new MemoryStream();
            var pdfExport = new PdfExport();

            pdfExport.Export(report.Document, memStream);
            memStream.Position = 0;
            var attachments = new Dictionary <string, MemoryStream> {
                { $"Quote {order.Id.ToString("0000")}.pdf", memStream }
            };

            var mailMessage = new SendGridMessage {
                Subject             = model.Subject,
                From                = new MailAddress(fromAddress, user.Identity.Name),
                Text                = model.Body,
                Html                = model.Body.Replace("\n", "<br>"),
                StreamedAttachments = attachments
            };
            var to = model.Address.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();

            if (to.Any())
            {
                mailMessage.AddTo(to);

                model.Bcc.ToList().ForEach(bcc => {
                    if (!string.IsNullOrWhiteSpace(bcc))
                    {
                        mailMessage.AddBcc(bcc);
                    }
                });
            }
            else
            {
                to = model.Bcc.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                mailMessage.AddTo(to);
            }

            var delivery = await _repo.RecordInvoiceEmail(mailMessage, order.Id, user.Identity.Name);

            mailMessage.AddUniqueArgs(new Dictionary <string, string> {
                ["order_id"]    = order.Id.ToString(),
                ["delivery_id"] = delivery.Id.ToString()
            });

            try {
                var apiKey       = ConfigurationManager.AppSettings["SendGridApiKey"];
                var transportWeb = new Web(apiKey);
                await transportWeb.DeliverAsync(mailMessage);
            } catch (InvalidApiRequestException ex) {
                var       errorMessage = string.Join(", ", ex.Errors);
                Exception error        = ex;
                while (error != null)
                {
                    errorMessage += $",{error.Message}";
                    error         = error.InnerException;
                }
                await _repo.LogEmailDeliveryError(delivery.Id, errorMessage);

                throw;
            } catch (Exception ex) {
                var errorMessage = string.Empty;
                var error        = ex;
                while (error != null)
                {
                    errorMessage += $",{error.Message}";
                    error         = error.InnerException;
                }
                await _repo.LogEmailDeliveryError(delivery.Id, errorMessage);

                throw;
            }

            var email = string.Join(";", model.Address);

            if (!string.IsNullOrWhiteSpace(email))
            {
                order.Inquiry.Email = email;
            }
            if (order.InvoiceDate == null)
            {
                order.InvoiceDate = DateTime.Now;
            }
            await _repo.Edit(order, user.Identity.Name);

            return(Ok(delivery));
        }