public void Delete(Broadcast request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityBroadcast.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No Broadcast 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.BROADCAST); DocCacheClient.RemoveById(request.Id); }); } }
private Broadcast GetBroadcast(Broadcast request) { var id = request?.Id; Broadcast ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Broadcast>(currentUser, "Broadcast", request.Select); DocEntityBroadcast entity = null; if (id.HasValue) { entity = DocEntityBroadcast.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Broadcast 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 Broadcast Post(BroadcastCopy request) { Broadcast ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityBroadcast.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 pApp = entity.App; var pConfluenceId = entity.ConfluenceId; if (!DocTools.IsNullOrEmpty(pConfluenceId)) { pConfluenceId += " (Copy)"; } var pName = entity.Name; if (!DocTools.IsNullOrEmpty(pName)) { pName += " (Copy)"; } var pReprocess = entity.Reprocess; var pReprocessed = entity.Reprocessed; var pScopes = entity.Scopes.ToList(); var pStatus = entity.Status; var pType = entity.Type; var copy = new DocEntityBroadcast(ssn) { Hash = Guid.NewGuid() , App = pApp , ConfluenceId = pConfluenceId , Name = pName , Reprocess = pReprocess , Reprocessed = pReprocessed , Status = pStatus , Type = pType }; foreach (var item in pScopes) { entity.Scopes.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }