public StatusCodeResult ReCaptchaVerify(string captchaResponse)
        {
            Visitor visitor = null;

            try
            {
                IRestResponse reCaptcha;
                _context.Database.EnsureCreated();
                visitor = Functions.EntityFW.InitializeVisitor(_context, _accessor);
                //log
                Functions.Log.LogActivity(_context, "g-recaptchaVerify", "Sending captcha for verification", visitor);

                //reCaptcha verify
                RequestFactory RC          = new RequestFactory();
                RestRequest    restRequest = RC.RequestConstructor(
                    new Dictionary <string, string>()
                {
                    { "secret", secretKey },
                    { "response", captchaResponse },
                    { "remoteip", visitor.IpAdress }
                },
                    Method.POST);
                reCaptcha = RC.RequestSender(url, restRequest);

                //log
                Functions.Log.LogActivity(_context, "g-recaptchaVerify", "Received captcha for verification", visitor);

                _context.SaveChanges();


                //Check if captcha was successful or not
                //if(reCaptcha.Content.Contains('"'+"success"+'"'+": true"))
                if (reCaptcha.Content.Contains("true"))
                {
                    Functions.Log.LogActivity(_context, "g-recaptchaVerify", "Captcha is valid", visitor);
                    HttpContext.Session.SetString("captcha", "verified");
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                Functions.Log.LogError(_context, "Index-Captcha verify", e.ToString(), visitor ?? EntityFW.InitializeVisitor(_context, _accessor));
            }
            Functions.Log.LogActivity(_context, "g-recaptchaVerify", "Captcha is invalid", visitor);
            return(BadRequest());
        }
        public IActionResult RequestForm(string songRequest, string email, string bandName, string bandLocation, bool GDPRConsent)
        {
            Visitor visitor = null;

            try
            {
                //validify all input
                if (HttpContext.Session.GetString("captcha") != "verified" || String.IsNullOrEmpty(HttpContext.Session.GetString("captcha")))
                {
                    return(BadRequest("Please verify that you are human"));
                }
                if (!Functions.Validify.IsValidEmail(email))
                {
                    return(BadRequest("Invalid email"));
                }
                if (String.IsNullOrEmpty(songRequest) || String.IsNullOrEmpty(bandName) || String.IsNullOrEmpty(bandLocation))
                {
                    return(BadRequest("Please fill up all form fields"));
                }
                if (!GDPRConsent)
                {
                    return(BadRequest("You have to agree with our Privacy Policy"));
                }

                songRequest = HttpUtility.HtmlEncode(songRequest);
                bandName    = HttpUtility.HtmlEncode(bandName);
                _context.Database.EnsureCreated();

                visitor = EntityFW.InitializeVisitor(_context, _accessor);
                //Log
                Functions.Log.LogActivity(_context, "Index", "Sending form", visitor);

                //Check if band exists if not, create one
                Band band = _context.Band.Where(v => v.BandName == bandName).FirstOrDefault() ?? new Band
                {
                    BandName     = bandName,
                    BandLocation = bandLocation
                };
                User user = _context.User.Where(v => v.Email == email).FirstOrDefault() ?? new User {
                    Email       = email,
                    ConsentGdpr = GDPRConsent
                };

                UserHasVisitor UHV = _context.UserHasVisitor.Where(v => v.UserIdUserNavigation == user && v.VisitorIdVisitorNavigation == visitor).FirstOrDefault();
                if (UHV == null)
                {
                    UHV = new UserHasVisitor {
                        UserIdUserNavigation       = user,
                        VisitorIdVisitorNavigation = visitor
                    };
                    _context.UserHasVisitor.Add(UHV);
                }
                BandHasUser BHU = _context.BandHasUser.Where(v => v.UserIdUserNavigation == user && v.BandIdBandNavigation == band).FirstOrDefault();
                if (BHU == null)
                {
                    BHU = new BandHasUser {
                        UserIdUserNavigation = user,
                        BandIdBandNavigation = band
                    };
                    _context.BandHasUser.Add(BHU);
                }
                //Create new song request
                SongRequest newSongRequest = new SongRequest
                {
                    SongRequest1     = songRequest,
                    IdUserNavigation = user
                };
                _context.SongRequest.Add(newSongRequest);
                string[] songs = EntityFW.GetSongs(songRequest);
                foreach (string song in songs)
                {
                    if (song.Contains("open.spotify.com") || song.Contains("youtube.com"))
                    {
                        _context.Song.Add(new Song {
                            SongUrl = song,
                            IdSongRequestNavigation = newSongRequest,
                            IdBandNavigation        = band
                        });
                    }
                    else
                    {
                        Functions.Log.LogError(_context, "Index-Send - Form - Invalid song url", song, visitor);
                    }
                }

                try
                {
                    Functions.Mail.SendMail("New song request", stringBuilder.Append("Band: ").Append(bandName).Append(" - From: ").Append(bandLocation).Append(" - Email: ").Append(email).Append("<br>Message:<br>").Append(songRequest).ToString());
                }
                catch (Exception e)
                {
                    Models.ErrorLog errorLog = new Models.ErrorLog();
                    errorLog.IdVisitorNavigation = visitor;
                    errorLog.Message             = e.Message;
                    errorLog.Source = "Index-Send Form Email - " + e.Source;
                    _context.ErrorLog.Add(errorLog);
                }
                _context.SaveChanges();
                return(Ok("Thank you!"));
            }
            catch (Exception e)
            {
                Functions.Log.LogError(_context, "Index-Send Form", e.ToString(), visitor ?? EntityFW.InitializeVisitor(_context, _accessor));
                return(BadRequest());
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("1.ADO.Net\n2.Entity FrameWork\n Enter Your Option:");
            int option = int.Parse(Console.ReadLine());

            if (option == 1)
            {
                try
                {
                    DbConnectivity connect = new DbConnectivity();
                    connect.connection();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine("1.Add Account\n2.View Account Details\n3.Withdrawl Amount\n4.Deposite Amount\nEnter the choice:");
                int ch = int.Parse(Console.ReadLine());
                switch (ch)
                {
                case 1:

                    BankOperation add = new BankOperation();
                    add.AddAcount();
                    break;

                case 2:

                    BankOperation details = new BankOperation();
                    details.AccountDetails();
                    break;

                case 3:

                    BankOperation withdraw = new BankOperation();
                    withdraw.Withdraw();
                    break;

                case 4:

                    BankOperation deposite = new BankOperation();
                    deposite.Deposite();
                    break;

                default:
                    Console.WriteLine("Wrong Choice:");
                    break;
                }
            }

            else if (option == 2)
            {
                Console.WriteLine("1.Add Account\n2.View Account Details\n3.Withdrawl Amount\n4.Deposite Amount\nEnter the choice:");
                int ch = int.Parse(Console.ReadLine());
                switch (ch)
                {
                case 1:

                    EntityFW add = new EntityFW();
                    add.AddAcount();
                    break;

                case 2:

                    EntityFW details = new EntityFW();
                    details.AccountDetails();
                    break;

                case 3:

                    EntityFW withdraw = new EntityFW();
                    withdraw.Withdraw();
                    break;

                case 4:

                    EntityFW deposite = new EntityFW();
                    deposite.Deposite();
                    break;

                default:
                    Console.WriteLine("Wrong Choice!");
                    break;
                }
            }
        }