public void Delete(File request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityFile.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No File could be found for Id {request?.Id}."); } if (en.IsRemoved) { return; } if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route."); } en.Remove(); DocCacheClient.RemoveSearch(DocConstantModelName.FILE); DocCacheClient.RemoveById(request.Id); }); } }
private File GetFile(File request) { var id = request?.Id; File ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <File>(currentUser, "File", request.Select); DocEntityFile entity = null; if (id.HasValue) { entity = DocEntityFile.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No File found for Id {id.Value}"); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route."); } ret = entity?.ToDto(); return(ret); }
public File Post(FileCopy request) { File ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityFile.Get(request?.Id); if (null == entity) { throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed."); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } var pCost = entity.Cost; var pFileLabel = entity.FileLabel; if (!DocTools.IsNullOrEmpty(pFileLabel)) { pFileLabel += " (Copy)"; } var pFileName = entity.FileName; if (!DocTools.IsNullOrEmpty(pFileName)) { pFileName += " (Copy)"; } var pOriginalFileName = entity.OriginalFileName; if (!DocTools.IsNullOrEmpty(pOriginalFileName)) { pOriginalFileName += " (Copy)"; } var pRights = entity.Rights; var pScopes = entity.Scopes.ToList(); var pSource = entity.Source; var pType = entity.Type; var copy = new DocEntityFile(ssn) { Hash = Guid.NewGuid() , Cost = pCost , FileLabel = pFileLabel , FileName = pFileName , OriginalFileName = pOriginalFileName , Rights = pRights , Source = pSource , Type = pType }; foreach (var item in pScopes) { entity.Scopes.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }