Exemplo n.º 1
0
        public void Index(IFormCollection formCollection)
        {
            //int personId = int.Parse(formCollection["PersonId"]);

            //id-t generálni
            Random r  = new Random();
            int    id = r.Next(1, 1024);

            while (_context.Donations.Find(id) != null)
            {
                id = r.Next(1, 1024);
            }

            string email    = formCollection["Email"];
            string wallet   = formCollection["Wallet"];
            int    usertype = int.Parse(formCollection["Usertype"]);

            double amount           = double.Parse(formCollection["Amount"]);
            string donatetimestring = formCollection["DonateTime"];

            DateTime donatetime;
            //DateTime.TryParse(donatetimestring, "YYYY-MM-DD HH:mm", out donatetime,);

            bool done = DateTime.TryParseExact(formCollection["DonateTime"], "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture,
                                               DateTimeStyles.None, out donatetime);



            if (ModelState.IsValid)
            {
                Donations newDonation = new Donations();
                newDonation.Id         = id;
                newDonation.Email      = email;
                newDonation.Wallet     = wallet;
                newDonation.Usertype   = usertype;
                newDonation.Amount     = amount;
                newDonation.DonateTime = donatetime;

                _context.Donations.Add(newDonation);
                _context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public String Index(IFormCollection formCollection)
        {
            String message = "";

            List <Subscribers> existingemail = _context.Subscribers.Where(p => p.Email.Equals(formCollection["Email"])).ToList();

            if (existingemail.Count == 0)
            {
                Random r  = new Random();
                int    id = r.Next(1, 1024);
                while (_context.Subscribers.Find(id) != null)
                {
                    id = r.Next(1, 1024);
                }

                string email = formCollection["Email"];


                if (ModelState.IsValid)
                {
                    Subscribers newSubscriber = new Subscribers();
                    newSubscriber.Id    = id;
                    newSubscriber.Email = email;

                    _context.Subscribers.Add(newSubscriber);
                    _context.SaveChanges();
                    message = "Success! Thank you for subscribing!";
                }
            }
            else
            {
                message = "Sorry, this e-mail already exists!";
            }

            return(message);
        }