public M.File Create(M.File model) { var file = new DB.File { ContentType = model.ContentType, Extension = model.Extension, GuidName = model.GuidName, Name = model.Name, Path = model.Path, ReferenceGuid = model.ReferenceGuid, Size = model.Size }; _fileRepo.Create(file); UnitOfWork.SaveChanges(); model.ID = file.ID; return(model); }
public JsonResult Save(Guid ReferenceGuid) { M.File file = new M.File(); try { foreach (string postedFile in Request.Files) { HttpPostedFileBase File = Request.Files[postedFile]; if (File != null && File.ContentLength > 0) { DirectoryInfo FilesFolder = new DirectoryInfo(string.Format("{0}\\Files", Server.MapPath(@"\"))); string Extension = Path.GetExtension(File.FileName); Guid GuidName = Guid.NewGuid(); string FileName = GuidName.ToString() + Extension; string FilePath = string.Format("{0}\\{1}", FilesFolder.ToString(), FileName); File.SaveAs(FilePath); file.ContentType = File.ContentType; file.Extension = Extension; file.GuidName = GuidName; file.Name = File.FileName; file.Path = FilePath; file.ReferenceGuid = ReferenceGuid; file.Size = File.ContentLength; file = _fileService.Create(file); } } } catch (Exception) { throw new HttpException(HttpStatusCode.InternalServerError.ToInt(), Definition.Message.Dropzone.Error); } return(Result(new Result <M.File>(file))); }