public ActionResult UploadFile()
        {
            var file = Request.Files[0];
            var myFile = new FileModel();
            myFile.FolderId = int.Parse(Request.QueryString.ToString());
            myFile.FileName = file.FileName;
            myFile.ContentType = file.ContentType;

            if (ModelState.IsValid)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    byte[] array = ms.GetBuffer();
                    myFile.FileContent = array;
                }
                _fileservice.AddFile(myFile.ToDomainWhithContent());

                return Json(string.Empty, JsonRequestBehavior.AllowGet);
            }
            else
            {
                Response.StatusCode = 400;
                var error = new ErrorModel();
                error.ErrorID = 4;
                error.Message = "Upload Faile";
                return Json(error, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #2
0
        public ActionResult Create(NewFileViewModel model, int?id)
        {
            if (!ModelState.IsValid)
            {
                //filtry
                //dodal service do obslugi bledow
                //ViewBag.Message = _helperService.ModelErrorsToString(ModelState);
                return(Create());
            }
            var userId = User.Identity.GetUserId();

            if (id == null)
            {
                id = _foldersService.GetRootId(userId);
            }
            var id_file = _filesService.AddFile(model, userId, id);

            return(RedirectToAction("Details", new { Id = id_file }));
        }