コード例 #1
0
        public async Task <IActionResult> Create(Product product, IList <IFormFile> PImages)
        {
            string AllFileNames = "";

            if (PImages != null && PImages.Count > 0)
            {
                foreach (IFormFile PImage in PImages)
                {
                    string FolderPath = ENV.ContentRootPath + "\\wwwroot\\Images\\ProductImages\\";
                    string FileName   = Guid.NewGuid() + Path.GetExtension(PImage.FileName);
                    PImage.CopyTo(new FileStream(FolderPath + FileName, FileMode.Create));
                    AllFileNames += (FileName + ",");
                }
            }



            if (ModelState.IsValid)
            {
                if (AllFileNames.Contains(','))
                {
                    AllFileNames = AllFileNames.Remove(AllFileNames.LastIndexOf(','));
                }

                product.Images = AllFileNames;
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
コード例 #2
0
        public async Task <IActionResult> Create(SystemUser systemUser, IFormFile UCV)
        {
            if (UCV != null)
            {
                //in bytes
                if (UCV.Length > 1000)
                {
                }
                string     FolderPath = ENV.ContentRootPath + "\\wwwroot\\Docs\\CVs\\";
                string     FileName   = Guid.NewGuid() + Path.GetExtension(UCV.FileName);
                FileStream FS         = new FileStream(FolderPath + FileName, FileMode.Create);;
                UCV.CopyTo(FS);
                systemUser.CV = FileName;
            }



            if (ModelState.IsValid)
            {
                ORM.Add(systemUser);
                await ORM.SaveChangesAsync();

                //send welcome email to user
                MailMessage oEmail = new MailMessage();

                oEmail.From = new MailAddress("*****@*****.**", "Theta Students");

                oEmail.To.Add(systemUser.Email);
                //oEmail.CC.Add("*****@*****.**");
                //oEmail.Bcc.Add("");

                oEmail.Subject = "Welcome to Theta Solutions";

                oEmail.Body = "<p><b>Welcome, " + systemUser.DisplayName + ",</b></p><br>" +

                              "Thank you for registering your account with Theta.<br>Please find below your account details and keep it safe<br><br>" +


                              "Username: "******"<br>" +
                              "Password: "******"<br style='color:red;'>Regards,<br>" +
                              "Support Team";

                ;

                oEmail.IsBodyHtml = true;

                if (System.IO.File.Exists("/Docs/CVs/" + systemUser.CV))
                {
                    oEmail.Attachments.Add(new Attachment("/Docs/CVs/" + systemUser.CV));
                }


                SmtpClient oSMTP = new SmtpClient();
                oSMTP.Host        = "smtp.gmail.com";
                oSMTP.Credentials = new System.Net.NetworkCredential("*****@*****.**", "YOUR_PASSWORD");
                oSMTP.Port        = 587; //25 465
                oSMTP.EnableSsl   = true;

                try
                {
                    oSMTP.Send(oEmail);
                }
                catch (Exception Ex)
                {
                }


                //send sms

                string SMSAPIURL = "https://sendpk.com/api/sms.php?username=923037226603&password=pakistan&sender=Masking&mobile=" + systemUser.Mobile + "&message=ThetaSolutions";


                WebRequest   request  = HttpWebRequest.Create(SMSAPIURL);
                WebResponse  response = request.GetResponse();
                StreamReader reader   = new StreamReader(response.GetResponseStream());
                string       urlText  = reader.ReadToEnd(); // it takes the response from your url. now you can use as your need

                if (urlText.Contains("OK"))
                {
                }



                return(RedirectToAction(nameof(Index)));
            }
            return(View(systemUser));
        }