internal void CreateNewStatistic()
        {
            Statistic statistics = new Statistic
            {
                Year      = DateTime.UtcNow.Year,
                Month     = DateTime.UtcNow.Month,
                Day       = DateTime.UtcNow.Day,
                Hour      = DateTime.UtcNow.Hour,
                IdSession = HttpContext.Current.Session.SessionID
            };

            using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
            {
                if (DHDomoticadbModel.Statistics.FirstOrDefault(x => x.IdSession == IdSession) == null)
                {
                    DHDomoticadbModel.Statistics.Add(statistics);
                    DHDomoticadbModel.SaveChanges();
                }
            }
        }
 //Aanpassen aan CRUD. Cookies eruit.
 internal void EditExistingUser(int ID)
 {
     // var con = System.Web.HttpContext.Current.Request.Cookies;
     using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
     {
         User user = DHDomoticadbModel.Users.FirstOrDefault(x => x.ID == ID);
         {
             user.Password       = Password;
             user.AdminID        = AdminID;
             user.FirstName      = FirstName;
             user.LastName       = LastName;
             user.Gender         = Gender;
             user.Country        = Country;
             user.Province       = Province;
             user.City           = City;
             user.ZipCode        = ZipCode;
             user.BillingAddress = BillingAddress;
         };
         {
             DHDomoticadbModel.SaveChanges();
         }
     }
 }
        internal void ChangeExistingUser()
        {
            var con     = System.Web.HttpContext.Current.Request.Cookies;
            var idCheck = Convert.ToInt32(con["UserID"].Value);

            using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
            {
                User user = DHDomoticadbModel.Users.FirstOrDefault(x => x.ID == idCheck);
                {
                    user.FirstName      = FirstName;
                    user.LastName       = LastName;
                    user.Gender         = Gender;
                    user.EMail          = EMail;
                    user.Country        = Country;
                    user.Province       = Province;
                    user.City           = City;
                    user.ZipCode        = ZipCode;
                    user.BillingAddress = BillingAddress;
                };
                {
                    DHDomoticadbModel.SaveChanges();
                }
            }
        }
Exemplo n.º 4
0
        private Payment CreatePayment(APIContext apiContext, string redirectUrl)
        {
            var listItems = new ItemList()
            {
                items = new List <Item>()
            };
            List <ItemModel> Order = (List <ItemModel>)Session["cart"];
            int totaal             = 0;

            foreach (var item in Order)
            {
                int prijs = Convert.ToInt16(Math.Round(item.Product.Price));
                listItems.items.Add(new Item()
                {
                    name     = item.Product.Name,
                    currency = "EUR",
                    price    = prijs.ToString(),
                    quantity = item.Quantity.ToString(),
                    sku      = "sku"
                });
                totaal += prijs * item.Quantity;

                using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
                {
                    var stock = DHDomoticadbModel.Products.FirstOrDefault(x => x.ID == item.Product.ID).Stock;

                    Session["stock"] = stock - item.Quantity;

                    DHDomoticadbModel.Products.FirstOrDefault(x => x.ID == item.Product.ID).Stock = stock - item.Quantity;
                    DHDomoticadbModel.SaveChanges();
                }
                Session["Totaal"] = totaal;
            }

            var payer = new Payer()
            {
                payment_method = "paypal"
            };
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };


            var details = new Details()
            {
                tax      = "0",
                shipping = "0",
                subtotal = Order.Sum(item => Convert.ToInt16(Math.Round(item.Product.Price)) * item.Quantity).ToString()
            };


            var amount = new Amount()
            {
                currency = "EUR",
                total    = (Convert.ToDouble(details.tax) + Convert.ToDouble(details.shipping) + Convert.ToDouble(details.subtotal)).ToString(),
                details  = details
            };


            var transactionList = new List <Transaction>();

            transactionList.Add(new Transaction()
            {
                description    = "Testing Transaction",
                invoice_number = Convert.ToString((new Random()).Next(100000)),
                amount         = amount,
                item_list      = listItems
            });


            payment = new Payment()
            {
                intent        = "sale",
                payer         = payer,
                transactions  = transactionList,
                redirect_urls = redirUrls
            };


            return(payment.Create(apiContext));
        }
        public ActionResult SignInPage(SignUpViewModel userModel)
        {
            var cookieExpDate = DateTime.UtcNow.AddDays(2);

            using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
            {
                if (userModel.Password == null || userModel.EMail == null)
                {
                    //geen geldige credentials ingevoerd (missend wachtwoord OF missend EmailAddress)
                    return(View("SignInPage", new SignUpViewModel()));
                }
                else
                {
                    var ePwd = Crypto.Hash(userModel.Password);
                    var x    = DHDomoticadbModel.Users.FirstOrDefault(u => u.EMail == userModel.EMail && u.Password == ePwd);
                    if (x == null)
                    {
                        //geen geldige credentials ingevoerd (geen combinatie van email + ww)
                        return(View("SignInPage", new SignUpViewModel()));
                    }
                    else
                    {
                        if (x != null) //Moet aan de checkbox worden verbonden. als deze niet gecheckt is komt hij in het bovenste, zowel dan in het onderste
                        {
                            if (!x.EmailConfirmed.Value)
                            {
                                ViewBag.Message = "U moet eerst uw emailadres bevestigen.";
                                return(View("SignInPage", new SignUpViewModel()));
                            }
                            //Geldige credentials ingevoerd
                            //Create Cookie
                            HttpCookie UserCookie     = new HttpCookie("UserEMail", x.EMail);
                            HttpCookie PwCookie       = new HttpCookie("UserPw", x.Password);
                            HttpCookie NameCookie     = new HttpCookie("UserName", x.FirstName);
                            HttpCookie LastNameCookie = new HttpCookie("UserLast", x.LastName);
                            HttpCookie IDCookie       = new HttpCookie("UserID", x.ID.ToString());
                            //HttpCookie UserNameCookie = new HttpCookie("UserName", userModel.FirstName.ToString());
                            //Expire Date of made cookie
                            UserCookie.Expires     = cookieExpDate;
                            PwCookie.Expires       = cookieExpDate;
                            NameCookie.Expires     = cookieExpDate;
                            LastNameCookie.Expires = cookieExpDate;
                            IDCookie.Expires       = cookieExpDate;

                            //Save data at Cookies
                            HttpContext.Response.SetCookie(UserCookie);
                            HttpContext.Response.SetCookie(PwCookie);
                            HttpContext.Response.SetCookie(NameCookie);
                            HttpContext.Response.SetCookie(LastNameCookie);
                            HttpContext.Response.SetCookie(IDCookie);

                            //Returns to index page
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            //Geldige credentials ingevoerd (en de checkbox aangevinkt)
                            //Create Cookie
                            HttpCookie UserCookie     = new HttpCookie("UserEMail", x.EMail);
                            HttpCookie PwCookie       = new HttpCookie("UserPw", x.Password);
                            HttpCookie NameCookie     = new HttpCookie("UserName", x.FirstName);
                            HttpCookie LastNameCookie = new HttpCookie("UserLast", x.LastName);
                            HttpCookie IDCookie       = new HttpCookie("UserID", x.ID.ToString());

                            //Save data at Cookies
                            HttpContext.Response.SetCookie(UserCookie);
                            HttpContext.Response.SetCookie(PwCookie);
                            HttpContext.Response.SetCookie(NameCookie);
                            HttpContext.Response.SetCookie(LastNameCookie);
                            HttpContext.Response.SetCookie(IDCookie);
                            //Returns to index page
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }
            }
        }
 public HomeController()
 {
     _context = new DHDomoticaDBEntities();
 }
Exemplo n.º 7
0
        public ActionResult Index(string caseSwitch)
        {
            //Zet de jaar, maand en dag op de komende huidige dag
            var year   = DateTime.UtcNow.Day;
            var month  = DateTime.UtcNow.Month;
            var day    = DateTime.UtcNow.Year;
            var number = 0;

            List <DataPoint> MonthlyVisitors = new List <DataPoint>();
            int tabel      = 0;
            int increments = 0;

            //string caseSwitch = "1 maand";
            switch (caseSwitch)
            {
            case "Afgelopen Week":
                tabel      = 7;
                increments = 1;
                break;

            case "Afgelopen Maand":
                tabel      = 30;
                increments = 1;
                break;

            case "Afgelopen 3 Maanden":
                tabel      = 90;
                increments = 1;
                break;

            case "Afgelopen Jaar":
                tabel      = 365;
                increments = 1;
                break;
            }

            // De forloop zorgt ervoor dat er 30 dagen worden gecontroleerd in de database en deze in de array zetten om een plaatje ervan te maken
            for (int i = tabel; i >= 0; i = i - increments)
            {
                var test = DateTime.UtcNow.AddDays(-i);
                year  = test.Year;
                month = test.Month;
                day   = test.Day;

                string stringDay   = test.Day.ToString();
                string stringMonth = test.ToString("MMM");

                using (DHDomoticaDBEntities DHDomoticadbModel = new DHDomoticaDBEntities())
                {
                    var hello = DHDomoticadbModel.Statistics.Where(z => z.Month == month && z.Year == year && z.Day == day).ToArray();
                    number = hello.Length;
                    DHDomoticadbModel.SaveChanges();
                }

                MonthlyVisitors.Add(new DataPoint(stringDay + " " + stringMonth, number));
            }

            ViewBag.MonthlyVisitors = JsonConvert.SerializeObject(MonthlyVisitors);

            ShowAdminSidebar();
            return(View());
        }