示例#1
0
        public ActionResult Edit(Guid? id)
        {
            AFile file = new AFile();
            if (id != null)
            {
                file = reposetory.GetFile((Guid)id);

            }
            return View(file);
        }
示例#2
0
        public ActionResult Edit(AFile postFile, IEnumerable<HttpPostedFileBase> files)
        {
            string errorMessage = "";

            if (files != null && files.Count() > 0)
            {
                // Get one only
                var file = files.FirstOrDefault();
                // Check if the file is an image
                if (file != null && IsValid(file))
                {
                    // Verify that the user selected a file
                    if (file != null && file.ContentLength > 0)
                    {
                        AFile theFile = new AFile();
                        if (postFile.FileID != Guid.Empty) theFile = reposetory.GetFile(postFile.FileID);
                        if (theFile == null) theFile = new AFile();
                        switch (Path.GetExtension(file.FileName).ToLower())
                        {
                            case ".jpeg":
                            case ".jpg":
                                theFile.Type = ".jpg";
                                break;
                            case ".pdf":
                                theFile.Type = ".pdf";
                                break;
                            case ".ppt":
                                theFile.Type = ".ppt";
                                break;
                            case ".pptx":
                                theFile.Type = ".pptx";
                                break;
                            case ".doc":
                                theFile.Type = ".doc";
                                break;
                            case ".docx":
                                theFile.Type = ".docx";
                                break;
                            case ".xls":
                                theFile.Type = ".xls";
                                break;
                            case ".xlsx":
                                theFile.Type = ".xlsx";
                                break;

                        }
                        theFile.Title = string.IsNullOrWhiteSpace(postFile.Title) ? Path.GetFileNameWithoutExtension(file.FileName) : postFile.Title;
                        theFile.Description = postFile.Description;
                        if (reposetory.Save(theFile))
                        {
                            var webPath = SaveFile(file, theFile.FileID);
                            if (Request.IsAjaxRequest())
                            {
                                return Json(new { success = true, fileName = webPath.Replace("/", "\\") }); // success
                            }
                            ViewBag.FormSucces = true;
                            return View("Edit", postFile);
                        }
                    }
                    errorMessage = General.FileUploadZeroLength; //failure
                }
                errorMessage = General.FileUploadWrongFormat; //failure
            }
            errorMessage = General.FileUploadNoUploaded; //failure
            if (Request.IsAjaxRequest())
                            {
            return Json(new { success = false, errorMessage = errorMessage });
                            }
            return View("Edit", postFile);
        }
示例#3
0
        private bool FileExists(AFile file)
        {
            string fullName = Server.MapPath(ConfigurationManager.AppSettings["FilesDir"] + "/" + file.FileID.ToString());
            return System.IO.File.Exists(fullName);

        }