Example #1
0
        public DragDropImage(string Product)
        {
            InitializeComponent();
            _productID = Product;
            _dataDC = new Model1Container();
            imagelist = new ObservableProductImage(_dataDC, _productID);

            ImageList.ItemsSource = imagelist;
        }
Example #2
0
        public static Boolean SendEmail(string ClientID, string ProductID,int Price)
        {
            Boolean EmailSent = true;
              Model1Container _dataDC = ModelSingleton.getDataDC;
              //Recover Client and Product Data
              ClientSet Client;

                  Client = _dataDC.ClientSet.First(S => S.Id == ClientID);
                  if (Client.Email != null && Client.Email != "")
                  {
                      ProductsSet Product;
                      Product = _dataDC.ProductsSet.First(S => S.Id == ProductID);
                      //Build the destination address
                      var toAddress = new MailAddress(Client.Email, Client.Name + " " + Client.Surname);
                      var fromAddress = new MailAddress(Properties.Settings.Default.EmailAddress, "Jose Maria Sanchez Colino");
                      //Set the password
                      const string fromPassword = "******";
                      //Build the subject
                      string subject = Product.Producto + " " + Product.Marca + " " + Product.Modelo;
                      //Build the body
                      string body = BuildBody(Product, Client, Price);

                      //collecting attached
                      List<ProductImageSet> ImageList = new ObservableProductImage(_dataDC, Product.Id).Where(S => S.Email== true).ToList();

                      var smtp = new SmtpClient
                      {
                          Host = "smtp.gmail.com",
                          Port = 587,
                          EnableSsl = true,
                          DeliveryMethod = SmtpDeliveryMethod.Network,
                          UseDefaultCredentials = false,
                          Credentials = new NetworkCredential(fromAddress.Address, fromPassword)

                      };
                      //Create the email
                      MailMessage message = new MailMessage(fromAddress, toAddress);
                      message.Subject = subject;
                      message.Body = body;
                      foreach (ProductImageSet Image in ImageList)
                      {
                          System.Net.Mail.Attachment attachment;
                          attachment = new System.Net.Mail.Attachment(Image.Path);
                          message.Attachments.Add(attachment);
                      }
                      try
                      {
                          smtp.Send(message);
                      }
                      catch (Exception e) { EmailSent = false; System.Windows.MessageBox.Show(e.ToString()); }
                  }
                  else System.Windows.MessageBox.Show("El cliente " + Client.Name + "no tiene asociado un correo electronico por lo que el correo no le sera enviado");
                  return EmailSent;
        }