コード例 #1
0
 public OperationDetails DeleteFile(FileDTO file)
 {
     FileEntity fileEntity = db.FileRepository.GetFileById(file.Id);
     if (fileEntity != null)
     {
         db.FileRepository.Delete(fileEntity);
         db.Commit();
         return new OperationDetails(true, "Файл успешно удален", "");
     }
     else
         return new OperationDetails(false, "Файл, который должен быть удален отсутствует", "Id");
 }
コード例 #2
0
 public OperationDetails CreateFile(FileDTO file)
 {
     FileEntity fileEntity = db.FileRepository.GetFileByName(file.FileName);
     if (fileEntity == null)
     {
         fileEntity = new FileEntity
         {
             ApplicationUserId = file.ApplicationUserId,
             FileBytes = file.FileBytes,
             FileName = file.FileName,
             IsPrivate = file.IsPrivate,
             FileType = MIMEAssistant.GetMIMEType(file.FileName),
             DownloadsCount = 0
         };
         db.FileRepository.Create(fileEntity);
         db.Commit();
         return new OperationDetails(true, "Файл успешно добавлен", "");
     }
     else return new OperationDetails(false, "Файл с таким именем уже существует", "FileName");
 }
コード例 #3
0
 public ActionResult CreateFile(HttpPostedFileBase upload)
 {
     if (upload != null)
     {
         byte[] fileBytes = null;
         string fileName = null;
         using (var binaryReader = new BinaryReader(upload.InputStream))
         {
             fileBytes = binaryReader.ReadBytes(upload.ContentLength);
             fileName = upload.FileName;
         }
         FileDTO file = new FileDTO
         {
             FileName = fileName,
             FileBytes = fileBytes,
             ApplicationUserId = User.Identity.GetUserId(),
             IsPrivate = false
         };
         OperationDetails result = FileService.CreateFile(file);
         if (!result.Succedeed)
             return RedirectToAction("CreateFile");
     }
     return RedirectToAction("Index", "User");
 }
コード例 #4
0
 private void SetOwnerName(FileDTO file)
 {
     if(file != null)
         file.OwnerName = db.UserManager.FindById(file.ApplicationUserId).UserName;
 }