public ActionResult Order()
        {
            int ID = (int)Session["kundID"];
            //BestallningMatratt ratt = new BestallningMatratt();

            Bestallning nyBestallning = new Bestallning();
            nyBestallning.KundID = ID;
            nyBestallning.BestallningDatum = DateTime.Now;
            nyBestallning.Totalbelopp = (int)TempData["TotalBelopp"];
            nyBestallning.Levererad = true;
            using (TomasosEntities db = new TomasosEntities())
            {

                db.Bestallnings.Add(nyBestallning);
                db.SaveChanges();

                int id = nyBestallning.BestallningID;

                foreach (var item in (List<Matratt>)Session["Varukorgen"])
                {
                    BestallningMatratt ratt = new BestallningMatratt();
                    ratt.MatrattID = item.MatrattID;
                    ratt.BestallningID = id;
                    ratt.Antal = 1;

                    db.BestallningMatratts.Add(ratt);
                    db.SaveChanges();
                }

            }

            Session["Varukorgen"] = null;
            return View();
        }
        public ActionResult Buy(int id)
        {
            using (TomasosEntities db = new TomasosEntities())
            {

                List<Matratt> selProduct = null;
                Matratt valdRatt = db.Matratts.SingleOrDefault(c => c.MatrattID == id);

                if (Session["Varukorgen"] == null)
                {
                    selProduct = new List<Matratt>();
                    selProduct.Add(valdRatt);
                }
                else
                {
                    selProduct = (List<Matratt>)Session["Varukorgen"];
                    selProduct.Add(valdRatt);

                }
                TempData["TotalBelopp"] = selProduct.Sum(o => o.Pris);
                ViewBag.TotalPris = selProduct.Sum(o => o.Pris);
                Session["Varukorgen"] = selProduct;

                return PartialView("_ViewPartialVarukorg", selProduct);

            }
        }
        // GET: Home
        public ActionResult Index()
        {
            using (TomasosEntities db = new TomasosEntities())
            {
                List<MatrattTyp> categoryList = db.MatrattTyps.Include("Matratts").ToList();

                return View(categoryList);
            }
        }
        public ActionResult MinaSidor()
        {
            using (TomasosEntities db = new TomasosEntities())
            {
                string userName = HttpContext.User.Identity.Name;
                Kund user = db.Kunds.SingleOrDefault(c => c.AnvandarNamn == userName);

                return View(user);
            }
        }
        public ActionResult MinaSidor(Kund user)
        {
            using (TomasosEntities db = new TomasosEntities())
            {
                Kund changedUserInfo = db.Kunds.SingleOrDefault(k => k.KundID == user.KundID);
                changedUserInfo.Namn = user.Namn;
                changedUserInfo.Gatuadress = user.Gatuadress;
                changedUserInfo.Postnr = user.Postnr;
                changedUserInfo.Postort = user.Postort;
                changedUserInfo.Email = user.Email;
                changedUserInfo.Telefon = user.Telefon;
                changedUserInfo.AnvandarNamn = user.AnvandarNamn;
                changedUserInfo.Losenord = user.Losenord;

                db.SaveChanges();
                ViewBag.Message = "Uppgifter ändrade";
                return View();
            }
        }
        public ActionResult Login(Kund user)
        {
            using (TomasosEntities db = new TomasosEntities())
            {
                Kund loggedUser = db.Kunds.SingleOrDefault(c => c.AnvandarNamn == user.AnvandarNamn && c.Losenord == user.Losenord);
                Session["kundID"] = loggedUser.KundID;

                if (loggedUser == null)
                {
                    ViewBag.ErrorLogin = "******";
                    return View();
                }

                else
                {
                    FormsAuthentication.SetAuthCookie(user.AnvandarNamn, false);
                    return RedirectToAction("Index", "Home");
                }

            }
        }
 public ActionResult Registrera(Kund nyKund)
 {
     using (TomasosEntities db = new TomasosEntities())
     {
         if (ModelState.IsValid)
         {
             db.Kunds.Add(nyKund);
             db.SaveChanges();
             return RedirectToAction("ValidReg");
         }
         else
         {
             return View();
         }
     }
 }