public ActionResult Edit([Bind(Include = "Id, name_for_schemaoccasion,description")] schemaOccasion schemaOccasion, string startTime, string endTime, string klassId, HttpPostedFileBase file)
        {
            schemaOccasion edit = db.occasions.Find(schemaOccasion.Id);
            edit.name_for_schemaoccasion = schemaOccasion.name_for_schemaoccasion;
            Klass klass = db.Klasser.Find(Int32.Parse(klassId));
                   
            if (ModelState.IsValid)
            {
                //schemaOccasion edit = db.occasions.Find(schemaOccasion.Id);
                //edit.name_for_schemaoccasion = schemaOccasion.name_for_schemaoccasion;
                edit.description = schemaOccasion.description;
                edit.startTime = DateTime.Parse(startTime);
                edit.endTime = DateTime.Parse(endTime);
                
                db.Entry(edit).State = EntityState.Modified;
                db.SaveChanges();
                
            }

            if (file.ContentLength > 0)
            {
                

                var fileName = Path.GetFileName(file.FileName);

                String strMappath = Server.MapPath("~/Filer/" + klass.Name + "/" + edit.name_for_schemaoccasion + "/shared/");
                if (!Directory.Exists(strMappath))
                {
                    DirectoryInfo di = Directory.CreateDirectory(strMappath);
                }

                var path = Path.Combine(strMappath, fileName);
                file.SaveAs(path);

                Fil fil = new Fil();
                fil.date = DateTime.Now;
                fil.filePath = path;
                fil.isShared = true;
                fil.owner = User.Identity.Name;
                fil.schemaOccasionId = schemaOccasion.Id;
                fil.fileName = fileName;
                db.Filer.Add(fil);
                db.SaveChanges();
                  
            }

            return RedirectToAction("Index/" + edit.KlassId);

            /*ViewBag.KlassId = new SelectList(db.Klasser, "Id", "TeacherId", schemaOccasion.KlassId);
            return View(schemaOccasion);*/
        }
        public ActionResult Details(HttpPostedFileBase file, String schemaOccasionId)
        {

            schemaOccasion occasion = db.occasions.Find(Int32.Parse(schemaOccasionId));
            Klass klass = db.Klasser.Find(occasion.KlassId);

            if (file!=null && file.ContentLength > 0)
            {
                String Name = User.Identity.Name;
                
                var fileName = Path.GetFileName(file.FileName);

                //Spara fil i mappsystemet:
                String strMappath = Server.MapPath("~/Filer/" + klass.Name + "/" +occasion.name_for_schemaoccasion + "/submit/" + Name);
                if (!Directory.Exists(strMappath))
                {
                    DirectoryInfo di = Directory.CreateDirectory(strMappath);
                }

                var path = Path.Combine(strMappath, fileName);
                file.SaveAs(path);

                //Spara i databas, knuten till klassen som ges, schemaOccasion och student:
                Fil fil = new Fil();
                using (var reader = new System.IO.BinaryReader(file.InputStream))
                {
                    fil.Content = reader.ReadBytes(file.ContentLength);
                }
                fil.ContentType = file.ContentType;
                fil.date = DateTime.Now;
                fil.fileName = file.FileName;
                //skippa filepath.. 
                //fil.fileType skippa..
                fil.isShared = false;
                fil.owner = User.Identity.GetUserId();
                fil.schemaOccasionId = Int32.Parse(schemaOccasionId);

                db.Filer.Add(fil);
                db.SaveChanges();
            }
            return RedirectToAction("Index/"+klass.Id);
        }