public async Task <IActionResult> Create([Bind("UserMain")] EventRegistrationVM eventRegistrationVM)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventRegistrationVM.UserMain);
                await _context.SaveChangesAsync();

                int ID = eventRegistrationVM.UserMain.ID;
                CS.MailSend(eventRegistrationVM.UserMain.Email, ID, "CSV"); // pass the csv file

                return(RedirectToAction(nameof(Index)));
            }
            await FillDropdown(eventRegistrationVM);

            return(View(eventRegistrationVM));
        }
Esempio n. 2
0
        public async Task UploadMemberCSV(string filepath)
        {
            try
            {
                MemberDetails member = new MemberDetails();
                var           lines  = System.IO.File.ReadAllLines(filepath);
                if (lines.Count() == 0)
                {
                    return;
                }
                var columns   = lines[0].Split(',');
                var table     = new DataTable();
                var tableSeat = new DataTable();
                foreach (var c in columns)
                {
                    table.Columns.Add(c);
                }

                for (int i = 1; i < lines.Count(); i++)
                {
                    table.Rows.Add(lines[i].Split(','));
                }

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    member.ID          = 0;
                    member.UserID      = Convert.ToInt32(table.Rows[i][0].ToString());
                    member.Name        = table.Rows[i][1].ToString();
                    member.NoOfMembers = Convert.ToInt32(table.Rows[i][2].ToString());
                    member.SeatNo      = table.Rows[i][3].ToString();
                    member.Meal1       = table.Rows[i][4].ToString().ToUpper().Equals("TRUE");
                    member.Meal2       = table.Rows[i][5].ToString().ToUpper().Equals("TRUE");
                    member.Meal3       = table.Rows[i][6].ToString().ToUpper().Equals("TRUE");
                    member.IsVeg       = table.Rows[i][7].ToString().ToUpper().Equals("TRUE");
                    member.Email       = table.Rows[i][8].ToString();
                    //member.IsInvitationSent = table.Rows[i][9].ToString().ToUpper().Equals("TRUE");
                    //member.IsReminderSent = table.Rows[i][10].ToString().ToUpper().Equals("TRUE");

                    if (i == 0)
                    {
                        _context.DeleteMembers(Convert.ToInt32(member.UserID));
                        //await _context.SaveChangesAsync();
                    }

                    _context.Add(member);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 3
0
        public async Task SendInvitation(bool IsRemind = false)
        {
            try
            {
                var list = await _context.UserMain.Where(x => x.EventDate >= DateTime.Now.Date).
                           Include(x => x.HallDetail).Include(x => x.EventType).
                           Include(x => x.EventSetup).Include(x => x.MemberDetailsList).ToListAsync();

                //var list = await _context.UserMain.Where(x => x.InviteDate <= DateTime.Now.Date).
                //Include(x => x.HallDetail).Include(x => x.EventType).
                //Include(x => x.EventSetup).Include(x => x.MemberDetailsList).ToListAsync();

                //.Where(z => z.IsInvitationSent == false)

                //var a = await _context.UserMain.Where(x => x.InviteDate <= DateTime.Now.Date).ToListAsync();



                var x = list;
                foreach (var evnt in list)
                {
                    if (evnt.MemberDetailsList != null)
                    {
                        foreach (var member in evnt.MemberDetailsList)
                        {
                            if (member.Email != null && member.Email != "")
                            {
                                bool state;
                                if (IsRemind)
                                {
                                    state = member.IsReminderSent;
                                }
                                else
                                {
                                    state = member.IsInvitationSent;
                                }
                                if (!state)
                                {
                                    //string code = txtCode.Text;
                                    QRCodeGenerator qrGenerator = new QRCodeGenerator();
                                    //QRCodeData qrdata = qrGenerator.CreateQrCode(inputText, QRCodeGenerator.ECCLevel.Q);
                                    QRCodeData qrdata = qrGenerator.CreateQrCode(Convert.ToString(member.ID), QRCodeGenerator.ECCLevel.Q);
                                    QRCode     qrCode = new QRCode(qrdata);
                                    using (Bitmap bitMap = qrCode.GetGraphic(20))
                                    {
                                        MemoryStream ms = new MemoryStream();
                                        //bitMap.Save(ms.MapPath("~/Images/qrcode.png"), ImageFormat.Png);
                                        bitMap.Save(ms, ImageFormat.Jpeg);
                                        byte[]   byteImage = ms.ToArray();
                                        Image    qrimg     = Image.FromStream(ms);
                                        string   path      = @Directory.GetCurrentDirectory() + @"\QRCodeTempSave\";
                                        string   imgname   = "QRCode" + "-" + member.UserID + "-" + member.ID + ".Jpeg";
                                        FileInfo file      = new FileInfo(path + imgname);
                                        if (!file.Exists)
                                        {
                                            qrimg.Save(path + imgname, ImageFormat.Jpeg);
                                        }

                                        string ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);

                                        MailMessage mm = new MailMessage();
                                        mm.From = new MailAddress("*****@*****.**");
                                        if (IsRemind)
                                        {
                                            mm.Subject            = "Reminder for " + evnt.Name + " " + evnt.EventType.Type + " Event";
                                            member.IsReminderSent = true;
                                        }
                                        else
                                        {
                                            mm.Subject = "Invitation for " + evnt.Name + " " + evnt.EventType.Type + " Event";
                                            member.IsInvitationSent = true;
                                        }

                                        string        mailbody           = "Dear " + member.Name + ", <br/><html><body><p>Your are invited to participate the <b>" + evnt.Name + " " + evnt.EventType.Type + "</b> event on <b>" + evnt.EventDate.ToString("dddd, dd MMMM yyyy hh:mm tt") + "</b> at <b>" + evnt.HallDetail.Name + "</b> on BMICH.</p><h3>QR Code</h3><img src=\"cid:Email\"  width='200' height='200'><br><h3>Scaning steps:</h3><p style='color:DodgerBlue'>1.produce the qr code in registration desk</p><p style='color:DodgerBlue'>2.get the seat no and meal tokens printed there</p><br><p>Best Regards!</p><p>" + evnt.Name + "</p></body></html>";
                                        AlternateView AlternateView_Html = AlternateView.CreateAlternateViewFromString(mailbody, null, MediaTypeNames.Text.Html);
                                        // Create a LinkedResource object and set Image location path and Type
                                        LinkedResource Picture1 = new LinkedResource(path + imgname, MediaTypeNames.Image.Jpeg);
                                        Picture1.ContentId = "Email";
                                        AlternateView_Html.LinkedResources.Add(Picture1);
                                        mm.AlternateViews.Add(AlternateView_Html);
                                        mm.Body = mailbody;

                                        //mm.To.Add("*****@*****.**");
                                        mm.To.Add(Convert.ToString(member.Email));
                                        mm.IsBodyHtml = true;
                                        SmtpClient smtp = new SmtpClient();
                                        smtp.Host      = "smtp.gmail.com";
                                        smtp.EnableSsl = true;
                                        NetworkCredential NetworkCred = new NetworkCredential();
                                        NetworkCred.UserName       = "******";
                                        NetworkCred.Password       = "******";
                                        smtp.UseDefaultCredentials = false;
                                        smtp.Credentials           = NetworkCred;
                                        smtp.Port = 587;

                                        smtp.Send(mm);
                                        _context.Update(member);
                                        await _context.SaveChangesAsync();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }