public void Delete(VariableInstance request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityVariableInstance.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No VariableInstance 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.VARIABLEINSTANCE); DocCacheClient.RemoveById(request.Id); }); } }
private VariableInstance GetVariableInstance(VariableInstance request) { var id = request?.Id; VariableInstance ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <VariableInstance>(currentUser, "VariableInstance", request.Select); DocEntityVariableInstance entity = null; if (id.HasValue) { entity = DocEntityVariableInstance.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No VariableInstance 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 VariableInstance Post(VariableInstanceCopy request) { VariableInstance ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityVariableInstance.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 pData = entity.Data; var pDocument = entity.Document; var pRule = entity.Rule; var pWorkflows = entity.Workflows.ToList(); var copy = new DocEntityVariableInstance(ssn) { Hash = Guid.NewGuid() , Data = pData , Document = pDocument , Rule = pRule }; foreach (var item in pWorkflows) { entity.Workflows.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }