Ejemplo n.º 1
0
        public ActionResult UploadPackage(HttpPostedFileBase file)
        {
            if (file == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // save file into memory stream
            using (var memoryStream = new MemoryStream())
            {
                file.InputStream.Position = 0;
                while (file.InputStream.Position < file.InputStream.Length)
                {
                    var dataSinge = (byte)file.InputStream.ReadByte();
                    memoryStream.WriteByte(dataSinge);
                }

                // get the module info from stream
                try
                {
                    IModuleInfo moduleInfo = _zipPackager.UnPack(memoryStream.ToArray());
                    _repositoryModel.AddModule(moduleInfo);
                }
                catch (Exception e)
                {
                    ViewData["Message"] = e.Message;
                    return(View("Error"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }