public async Task <IActionResult> Create([Bind("Id,Name,ShortDescription,LongDescription,CurrentStock,CostPrice,SalePrice,ProductCode,Status,OpeningStock,OpeningDate,ProductFeatures,CreatedBy")] 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 (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
            }
            if (ModelState.IsValid)
            {
                if (AllFileNames.Contains(','))
                {
                    AllFileNames = AllFileNames.Remove(AllFileNames.LastIndexOf(','));
                }
                product.Images = AllFileNames;
                ORM.Add(product);
                await ORM.SaveChangesAsync();

                TempData["Message"] = product.Name + " Successfully added";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Picture,Status,ShortDescription,LongDescription,CreateDate,CreatedBy,ModifiedDate,ModifiedBy")] Category category, IFormFile CImage)
        {
            string FileName = "";

            if (CImage != null)
            {
                string FTPFolderPath = ENV.ContentRootPath + "\\wwwroot\\Images\\CategoryImages";

                string FileExt = Path.GetExtension(CImage.FileName);

                FileName = Guid.NewGuid() + FileExt;
                string FinalFilePath = FTPFolderPath + "\\" + FileName;



                FileStream FS = new FileStream(FinalFilePath, FileMode.Create);

                CImage.CopyTo(FS);
            }
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
            }
            if (ModelState.IsValid)
            {
                category.Picture = FileName;
                ORM.Add(category);
                await ORM.SaveChangesAsync();

                TempData["Message"] = category.Name + " Successfully added";
                HttpContext.Session.SetString("CNAME", category.Name);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Example #3
0
        public async Task <IActionResult> Register(SystemUser user, 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);
                user.CV = FileName;
            }



            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
            }

            ORM.SystemUser.Add(user);
            await ORM.SaveChangesAsync();

            // ORM.SaveChanges();
            TempData["Message"] = user.UserName + "Successfully Registered";
            //send welcome email to user
            MailMessage oEmail = new MailMessage();

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

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

            oEmail.Subject = "Welcome to Theta Solutions";

            oEmail.Body = "<p><b>Welcome, " + user.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/" + user.CV))
            {
                oEmail.Attachments.Add(new Attachment("/Docs/CVs/" + user.CV));
            }


            SmtpClient oSMTP = new SmtpClient();

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

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


            //send sms

            string SMSAPIURL = "https://sendpk.com/api/sms.php?username=923479389419&password=123456&sender=Masking&mobile=" + user.Mobile + "&message=asif khattak";


            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(View());
        }