Пример #1
0
        public ResponseBase SendMessage(string To, string Subject, string Message)
        {
            ResponseBase response = new ResponseBase();

            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  smtpServer = new SmtpClient(ConfigurationManager.AppSettings["EmailHost"]);
                mail.Subject = Subject;
                mail.From    = new MailAddress(ConfigurationManager.AppSettings["EmailAddress"]);
                mail.To.Add(To);
                mail.Body              = Message;
                smtpServer.Port        = Convert.ToInt32(ConfigurationManager.AppSettings["EmailPortNumber"]);
                smtpServer.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["EmailAddress"], ConfigurationManager.AppSettings["EmailPassword"]);
                smtpServer.EnableSsl   = true;
                smtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                string methodName   = System.Reflection.MethodBase.GetCurrentMethod().Name;
                string source       = ex.Source;
                string stacktrace   = ex.StackTrace;
                string targetsite   = ex.TargetSite.ToString();
                string error        = ex.InnerException.ToString();
                string ErrorMessage = $"There was an error at {DateTime.Now} {Environment.NewLine} Method: {methodName} {Environment.NewLine} Source: {source} {Environment.NewLine} StackTrace: {stacktrace} {Environment.NewLine} TargetSite: {targetsite} {Environment.NewLine} Error: {error}{Environment.NewLine} To: {To}{Environment.NewLine} Subject: {Subject}{Environment.NewLine} Message: {Message} ";
                _applicaitonError.Log(ErrorMessage, string.Empty);
            }

            return(response);
        }
Пример #2
0
        public ResponseBase Add(OrderInfo Order)
        {
            ResponseBase response = new ResponseBase();

            try
            {
                using (var ctx = new SimpleCureEntities())
                {
                    var Added = ctx.OrderInfoes.Add(Order);

                    if (Added.ID > 0)
                    {
                        response.ResponseSuccess = true;
                        //confirm if they want this or not and if so change it to a PDF attachement that is sent which means we will have to conver the Order just received into a pdf then stream it to the email message piece as a attachment
                        _emailMessage.SendMessage(ConfigurationManager.AppSettings["EmailAddress"], "New Order Created", "A new order has been created.");
                    }
                    else
                    {
                        response.ResponseMessage = "Unable to add Order: " + Order;
                    }
                }
            }
            catch (Exception ex)
            {
                string obj          = JsonConvert.SerializeObject(Order);
                string methodName   = System.Reflection.MethodBase.GetCurrentMethod().Name;
                string source       = ex.Source;
                string stacktrace   = ex.StackTrace;
                string targetsite   = ex.TargetSite.ToString();
                string error        = ex.InnerException.ToString();
                string ErrorMessage = $"There was an error at {DateTime.Now} {Environment.NewLine} Method: {methodName} {Environment.NewLine} Source: {source} {Environment.NewLine} StackTrace: {stacktrace} {Environment.NewLine} TargetSite: {targetsite} {Environment.NewLine} Error: {error}{Environment.NewLine} Object: {obj}";
                _applicationError.Log(ErrorMessage, string.Empty);

                response.ResponseMessage = "Unable to add Order: " + Order;
            }

            return(response);
        }
Пример #3
0
        public ResponseBase Add(OrderInfo_Product Product)
        {
            ResponseBase response = new ResponseBase();

            try
            {
                using (var ctx = new SimpleCureEntities())
                {
                    var Added = ctx.OrderInfo_Product.Add(Product);

                    if (Added.ID > 0)
                    {
                        response.ResponseSuccess = true;
                        //confirm if this is needed or not
                        _emailMessage.SendMessage(ConfigurationManager.AppSettings["EmailAddress"], "Product added to Order", "A product has been added to a order.");
                    }
                    else
                    {
                        response.ResponseMessage = "Unable to add Products to Order with Product Info: " + Product;
                    }
                }
            }
            catch (Exception ex)
            {
                string obj          = JsonConvert.SerializeObject(Product);
                string methodName   = System.Reflection.MethodBase.GetCurrentMethod().Name;
                string source       = ex.Source;
                string stacktrace   = ex.StackTrace;
                string targetsite   = ex.TargetSite.ToString();
                string error        = ex.InnerException.ToString();
                string ErrorMessage = $"There was an error at {DateTime.Now} {Environment.NewLine} Method: {methodName} {Environment.NewLine} Source: {source} {Environment.NewLine} StackTrace: {stacktrace} {Environment.NewLine} TargetSite: {targetsite} {Environment.NewLine} Error: {error}{Environment.NewLine} Object: {obj}";
                _applicationError.Log(ErrorMessage, string.Empty);

                response.ResponseMessage = "Unable to add Products to Order with Product Info: " + Product;
            }

            return(response);
        }