コード例 #1
0
ファイル: RoomController.cs プロジェクト: assafyariv/PSG
        public ActionResult Create(room room, HttpPostedFileBase file)
        {
            if (ModelState.IsValid && file != null)
            {
                if (file.ContentLength > 0)
                {
                    var dir = Path.Combine(Server.MapPath("~/Content/Romms"), room.name);
                    Directory.CreateDirectory(dir);

                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(dir, fileName);
                    file.SaveAs(path);

                    string unpackDirectory = Path.GetFileNameWithoutExtension(file.FileName);
                    var pathUnpackDirectory = Path.Combine(dir, unpackDirectory);
                    Directory.CreateDirectory(pathUnpackDirectory);

                    using (ZipFile zip1 = ZipFile.Read(path))
                    {
                        // here, we extract every entry, but we could extract conditionally
                        // based on entry name, size, date, checkbox status, etc.
                        // TODO: Fix this crap later -assaf
                        foreach (ZipEntry e in zip1)
                        {
                            e.Extract(pathUnpackDirectory, ExtractExistingFileAction.OverwriteSilently);
                        }
                    }

                    room.location = "/BServer/Content/Romms/" + room.name + "/" + unpackDirectory;
                    db.rooms.Add(room);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return View(room);
        }
コード例 #2
0
ファイル: RoomController.cs プロジェクト: assafyariv/PSG
        public ActionResult Edit(room room)
        {
            if (ModelState.IsValid)
            {

                db.Entry(room).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(room);
        }