private Trial GetTrial(Trial request) { var id = request?.Id; Trial ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Trial>(currentUser, "Trial", request.Select); DocEntityTrial entity = null; if (id.HasValue) { entity = DocEntityTrial.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Trial 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 Trial Post(TrialCopy request) { Trial ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityTrial.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 pDocuments = entity.Documents.ToList(); var pName = entity.Name; if (!DocTools.IsNullOrEmpty(pName)) { pName += " (Copy)"; } var pParent = entity.Parent; var copy = new DocEntityTrial(ssn) { Hash = Guid.NewGuid() , Name = pName , Parent = pParent }; foreach (var item in pDocuments) { entity.Documents.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }