コード例 #1
0
ファイル: Service.svc.cs プロジェクト: StefanAniff/hb.trex
        public ServerResponse SendInvoiceEmailToCustomerInvoiceGroup(Invoice invoice)
        {
            try
            {
                _invoiceSender.SendInvoiceEmail(invoice.ID);
                _invoiceService.UpdateDeliveredDate(invoice.ID);

                return(new ServerResponse("Email send", true));
            }
            catch (InvalidOperationException iex)
            {
                LogError(iex);
                return(new ServerResponse("Failed to send email\nPlease check if all templates are uploaded and try again", false));
            }
            catch (Exception ex)
            {
                LogError(ex);
                return(new ServerResponse("Failed to send email", false));
            }
        }
コード例 #2
0
        public List <ServerResponse> FinalizeInvoices(List <int> invoiceIds, bool isPreview)
        {
            try
            {
                var list = new List <ServerResponse>();

                foreach (var invoiceId in invoiceIds)
                {
                    var respond = new ServerResponse("", false, invoiceId);

                    if (_invoiceService.InvoiceNumberGiven(invoiceId) && _invoiceService.InvoiceFileCreated(invoiceId))
                    {
                        respond.Success = true;
                    }

                    else
                    {
                        respond = _invoiceWorker.FinalizeInvoice(invoiceId, isPreview);

                        if (!isPreview && respond.Success)
                        {
                            bool toBeSent = _invoiceSender.SendToMail(invoiceId);

                            if (toBeSent)
                            {
                                bool gotSent;
                                try
                                {
                                    gotSent = _invoiceSender.SendInvoiceEmail(invoiceId);
                                }
                                catch (Exception ex)
                                {
                                    LogError(ex);
                                    respond.Response = ex.Message;
                                    gotSent          = false;
                                }

                                if (gotSent)
                                {
                                    _invoiceService.UpdateDeliveredDate(invoiceId);
                                    respond.Response = "Invoices sent";
                                }
                                else
                                {
                                    RollBack(invoiceId);
                                    respond.Success = false;
                                }
                            }
                            else
                            {
                                respond.Success  = true;
                                respond.Response = "Invoice must be printet";
                                respond.ToPrint  = true;
                            }
                        }
                    }
                    list.Add(new ServerResponse(respond.Response, respond.Success, invoiceId));
                }
                return(list);
            }
            catch (Exception ex)
            {
                LogError(ex);
                return(null);
            }
        }