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"); }
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"); }
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"); }
private void SetOwnerName(FileDTO file) { if(file != null) file.OwnerName = db.UserManager.FindById(file.ApplicationUserId).UserName; }