public void Delete(LookupTableBinding request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityLookupTableBinding.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableBinding 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.LOOKUPTABLEBINDING); DocCacheClient.RemoveById(request.Id); }); } }
private LookupTableBinding GetLookupTableBinding(LookupTableBinding request) { var id = request?.Id; LookupTableBinding ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <LookupTableBinding>(currentUser, "LookupTableBinding", request.Select); DocEntityLookupTableBinding entity = null; if (id.HasValue) { entity = DocEntityLookupTableBinding.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableBinding 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 LookupTableBinding Post(LookupTableBindingCopy request) { LookupTableBinding ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityLookupTableBinding.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 pBinding = entity.Binding; var pBoundName = entity.BoundName; if (!DocTools.IsNullOrEmpty(pBoundName)) { pBoundName += " (Copy)"; } var pLookupTable = entity.LookupTable; var pScope = entity.Scope; var pSynonyms = entity.Synonyms.ToList(); var pWorkflows = entity.Workflows.ToList(); var copy = new DocEntityLookupTableBinding(ssn) { Hash = Guid.NewGuid() , Binding = pBinding , BoundName = pBoundName , LookupTable = pLookupTable , Scope = pScope }; foreach (var item in pSynonyms) { entity.Synonyms.Add(item); } foreach (var item in pWorkflows) { entity.Workflows.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }