Exemple #1
0
        public void SendEmailtoClient(int reportID)
        {
            FaultReport fr        = new FaultsServ.FaultReportLogServiceClient().getFaultByID(reportID);
            int         accountID = (int)fr.AccountID;

            Common.User details = new UserServ.UserServiceClient().getUSerByAccountID(accountID);

            string body = "Dear " + "\n" + details.Name + " " + details.Surname;

            body += "<br />";
            body += " your ticket : " + fr.TicketNum + " regarding the fault has been updated";


            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                mail.To.Add(details.Email);
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = body;


                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl   = enableSSL;
                    smtp.Send(mail);
                }
            }
        }
Exemple #2
0
        public void SendEmailToClient(int accountID, Image img, int pid, MemoryStream stream, int ticketNum)
        {
            Product p = new ProductServ.ProductServiceClient().GetProductByID(pid);

            string username = Session["username"].ToString();

            Common.User details = new UserServ.UserServiceClient().getUSerByAccountID(accountID);

            string body = "Dear " + "\n" + details.Name + " " + details.Surname;

            body += "<br />";
            body += "The fault of the product" + p.Name + " has been reported and your ticket number is : " + ticketNum;
            body += "Also attached is your barcode.";

            Bitmap bm = new Bitmap(stream);

            bm.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg);
            //Attachment attachment = new Attachment(stream, "BarcodeImage.jpg");
            //img.Save(stream, ImageFormat.Jpeg);
            stream.Position = 0;

            //mail.Attachments.Add(new Attachment(stream, "image/jpg"));
            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                // mail.Attachments.Add(attachment);
                mail.Attachments.Add(new Attachment(stream, "Barcodeimg.jpg", "image/jpg"));
                mail.To.Add(details.Email);
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = body;


                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl   = enableSSL;
                    smtp.Send(mail);
                }
            }
        }
Exemple #3
0
        public void sendEmailToClient(int accountID, ReportModel rm)
        {
            BasketController bc = new BasketController();

            string data = Render(bc, "ShowReport", rm);


            //stream.Position = 0;
            string username = Session["username"].ToString();

            Common.User details = new UserServ.UserServiceClient().getUSerByAccountID(accountID);

            string body = "Dear " + "\n" + details.Name + " " + details.Surname + "";

            body += "<br />";
            body += "A PDF attachment has been sent regarding the " + rm.myProduct.Name + " with the fault details";

            // MemoryStream stream = new MemoryStream(byteArray);
            //  Attachment attachment = AttachmentHelper.CreateAttachment(data, "Report.pdf", TransferEncoding.Base64);
            // byte[] stringBytes = System.Text.Encoding.ASCII.GetBytes(data);
            // MemoryStream stream = new System.IO.MemoryStream(stringBytes);
            // //stream.Write(stringBytes, 0, stringBytes.Length);

            //stream.Position = 0;

            var          doc          = new Document();
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            doc.Open();

            doc.Add(new Paragraph("ELECTROS"));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Date From : " + rm.from.ToShortDateString() + "  Date To : " + rm.to.ToShortDateString()));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Item"));
            doc.Add(new Paragraph("ProductID   " + " " + "Name             " + " " + "Price             " + " " + " Date of Purchase        " + "    Warranty Expiry Date"));
            doc.Add(new Paragraph(rm.myProduct.ID + "              " + rm.myProduct.Name + "             " + rm.myProduct.Price +
                                  "             " + Convert.ToDateTime(rm.myOrder.DateOfPurchase).ToShortDateString() + "                     " + Convert.ToDateTime(rm.myOrder.WarrantyExpiryDate).ToShortDateString()));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph("Fault"));
            foreach (FaultLog fl in rm.myFaultLog)
            {
                doc.Add(new Paragraph("FaultID     " + "       " + "Date             " + " " + "Status                   " + " " + "Fault Description        "));
                doc.Add(new Paragraph(fl.FaultReportID + "              " + Convert.ToDateTime(fl.DateReport).ToShortDateString() + "       " + fl.Status + "                   " + fl.Description + " "));
                doc.Add(new Paragraph(""));
            }
            doc.Add(new Paragraph(""));
            writer.CloseStream = false;
            doc.Close();
            memoryStream.Position = 0;


            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                //mail.Attachments.Add(attachment);
                mail.Attachments.Add(new Attachment(memoryStream, "Report.pdf"));
                mail.To.Add(details.Email);
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = body;

                //+" "+data;


                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl   = enableSSL;
                    smtp.Send(mail);
                }
            }
        }
Exemple #4
0
        public ActionResult RegisterUser(RegistrationModel rm)
        {
            //continuation of code

            int roleID = 0;

            if (rm.Password.Length < 6)
            {
                TempData["Message"] = "Password needs to be longer";
                //ViewBag.Msg = "Password needs to be longer";
                //return Content("PAssword longer");
                return(RedirectToAction("RegisterUser"));
            }
            else
            {
                Account checkAccount = new AccountServ.AccountServiceClient().getAccountByUsername(rm.Username);
                User    checkEmail   = new UserServ.UserServiceClient().getUserByEmail(rm.Email);
                int     pin          = Convert.ToInt32(rm.PIN);
                Account checkPin     = new AccountServ.AccountServiceClient().getAccountByPin(pin);

                if (checkAccount == null && checkEmail == null && checkPin == null)
                {
                    Account a = new AccountServ.AccountServiceClient().getAccountByUsername(rm.Username);

                    string passpin = rm.Password + rm.PIN;
                    string token   = new AccountServ.AccountServiceClient().Encrypt(passpin);
                    TempData["Token"] = token;

                    List <int> add = new List <int>();
                    for (int i = 0; i < rm.roles.Count; i++)
                    {
                        if (rm.roles[i].Checked)
                        {
                            roleID = rm.myRole[i].ID;
                            add.Add(roleID);
                        }
                    }
                    int[] arraylist = add.ToArray();
                    //rm.myUser.Email = rm.myUser
                    //USer
                    rm.myUser.Name          = rm.Name;
                    rm.myUser.Surname       = rm.Surname;
                    rm.myUser.Email         = rm.Email;
                    rm.myUser.ResidanceName = rm.ResidanceName;
                    rm.myUser.StreetName    = rm.StreetName;
                    rm.myUser.Mobile        = rm.Mobile;
                    //Account
                    //rm.myAccount.Username = rm.Username;
                    //rm.myAccount.Password = rm.Password;
                    //// rm.myAccount.PIN = Convert.ToInt32(rm.PIN);
                    //rm.myAccount.PIN = Convert.ToInt32(rm.PIN);
                    Account acc = new Account();
                    acc.Username = rm.Username;
                    acc.Password = rm.Password;
                    acc.PIN      = rm.PIN;
                    //new UserServ.UserServiceClient().Create(rm.myUser, arraylist, rm.myAccount);
                    new UserServ.UserServiceClient().Create(rm.myUser, arraylist, acc);
                }
                else
                {
                    if (checkAccount != null)
                    {
                        TempData["Message"] = "Username already exists";
                    }
                    else if (checkEmail != null)
                    {
                        TempData["Email"] = "Email already exists";
                    }
                    else if (checkPin != null)
                    {
                        TempData["PIN"] = "PIN already exists";
                    }
                }
            }

            //return View("RegisterUser");
            return(RedirectToAction("RegisterUser"));
        }