Example #1
0
        public ActionResult ReportByEmail(EmailModel email)
        {
            var idd = Session["ClientID"];
            var cdd = Session["CompayID"];

            if (Session["ClientID"] != null && Session["CompayID"] != null)
            {
                Contectid = Convert.ToInt32(Session["ClientID"]);
                CompanyID = Convert.ToInt32(Session["CompayID"]);
            }

            TempData["EmailMessge"] = "";

            EmailModel emailModel = new EmailModel();
            var        fileName   = email.Attachment;

            try
            {
                if (email.Attachment.Contains(".pdf"))
                {
                    email.Attachment = email.Attachment.Replace(".pdf", "");
                }
                if (email.ToEmail.Contains(','))
                {
                    var p = email.Attachment.Split('.');

                    var root    = Server.MapPath("/PDF/");
                    var pdfname = String.Format("{0}.pdf", p);
                    var path    = Path.Combine(root, pdfname);
                    email.Attachment = path;
                    string[] EmailArray = email.ToEmail.Split(',');
                    if (EmailArray.Count() > 0)
                    {
                        foreach (var item in EmailArray)
                        {
                            emailModel.From       = email.From;
                            emailModel.ToEmail    = item;
                            emailModel.Attachment = email.Attachment;
                            emailModel.EmailBody  = email.EmailText;
                            bool result = EmailController.email(emailModel, _attackmentList);
                        }
                    }
                }
                else
                {
                    var root    = Server.MapPath("/PDF/");
                    var pdfname = String.Format("{0}.pdf", email.Attachment);
                    var path    = Path.Combine(root, pdfname);
                    email.Attachment      = path;
                    emailModel.From       = email.From;
                    emailModel.ToEmail    = email.ToEmail;
                    emailModel.Attachment = email.Attachment;
                    emailModel.EmailBody  = email.EmailText;
                    bool result = EmailController.email(emailModel, _attackmentList);
                    TempData["EmailMessge"] = "Email Send successfully";

                    return(RedirectToAction("Journal"));
                }
            }
            catch (Exception ex)
            {
                TempData["Message"] = "Email Send Succssfully";
                email.Attachment    = fileName;
            }
            return(View(email));
        }
        public ActionResult ExpenseByEmail(EmailModel email, string[] Files, FormCollection formCollection)
        {
            var root = Server.MapPath("/PDF/");

            List <AttakmentList> _attackmentList = new List <AttakmentList>();
            var allowedExtensions = new string[] { "doc", "docx", "pdf", ".jpg", "png", "JPEG", "JFIF", "PNG" };

            if (email.SelectList != null)
            {
                foreach (var item in email.SelectList)
                {
                    if (item.IsSelected)
                    {
                        if (item.Directory.EndsWith("doc") || item.Directory.EndsWith("pdf") || item.Directory.EndsWith("docx") || item.Directory.EndsWith("jpg") || item.Directory.EndsWith("png") || item.Directory.EndsWith("txt"))
                        {
                            if (System.IO.File.Exists(Server.MapPath(item.Directory)))
                            {
                                _attackmentList.Add(new AttakmentList {
                                    Attckment = Server.MapPath(item.Directory)
                                });
                            }

                            var filwe = Server.MapPath("/PDF/" + item.FileName);

                            if (System.IO.File.Exists(filwe))
                            {
                                _attackmentList.Add(new AttakmentList {
                                    Attckment = filwe
                                });
                            }
                        }
                    }
                }
            }


            if (Request.Form["FileName"] != null)
            {
                var      fileName2  = Request.Form["FileName"];
                string[] valueArray = fileName2.Split(',');

                foreach (var item in valueArray)
                {
                    if (item.EndsWith("doc") || item.EndsWith("pdf") || item.EndsWith("docx") || item.EndsWith("jpg") || item.EndsWith("png") || item.EndsWith("txt"))
                    {
                        var filwe = Server.MapPath("/PDF/" + item);
                        if (System.IO.File.Exists(filwe))
                        {
                            _attackmentList.Add(new AttakmentList {
                                Attckment = filwe
                            });
                        }
                    }
                }
            }


            TempData["EmailMessge"] = "";
            EmailModel emailModel = new EmailModel();


            var fileName = email.Attachment;

            try
            {
                if (email.Attachment.Contains(".pdf"))
                {
                    email.Attachment = email.Attachment.Replace(".pdf", "");
                }
                if (email.ToEmail.Contains(','))
                {
                    var p = email.Attachment.Split('.');

                    var pdfname = String.Format("{0}.pdf", p);
                    var path    = Path.Combine(root, pdfname);
                    email.Attachment = path;
                    _attackmentList.Add(new AttakmentList {
                        Attckment = email.Attachment
                    });
                    string[] EmailArray = email.ToEmail.Split(',');
                    if (EmailArray.Count() > 0)
                    {
                        foreach (var item in EmailArray)
                        {
                            emailModel.From       = email.From;
                            emailModel.ToEmail    = item;
                            emailModel.Attachment = email.Attachment;
                            emailModel.EmailBody  = email.EmailText;
                            bool result = EmailController.email(emailModel, _attackmentList);
                        }
                    }
                }
                else
                {
                    var pdfname = String.Format("{0}.pdf", email.Attachment);
                    var path    = Path.Combine(root, pdfname);
                    email.Attachment      = path;
                    emailModel.From       = email.From;
                    emailModel.ToEmail    = email.ToEmail;
                    emailModel.Attachment = email.Attachment;
                    emailModel.EmailBody  = email.EmailText;
                    _attackmentList.Add(new AttakmentList {
                        Attckment = emailModel.Attachment
                    });
                    bool result = EmailController.email(emailModel, _attackmentList);
                    TempData["EmailMessge"] = "Email Send successfully";
                }

                HttpResponseMessage res = GlobalVeriables.WebApiClient.GetAsync("APIQutation/" + email.invoiceId.ToString()).Result;
                MVCQutationModel    ob  = res.Content.ReadAsAsync <MVCQutationModel>().Result;

                var folderPath = Server.MapPath("/PDF/");
                EmailController.clearFolder(folderPath);
                return(RedirectToAction("ViewExpense", new { Id = email.invoiceId }));
            }
            catch (Exception ex)
            {
                TempData["EmailMessge"] = ex.Message.ToString();
                TempData["Error"]       = ex.Message.ToString();
            }
            if (TempData["Path"] == null)
            {
                TempData["Path"] = fileName;
            }

            TempData["Message"] = "Email Send Succssfully";
            email.Attachment    = fileName;

            return(View(email));
        }