private Attribute GetAttribute(Attribute request) { var id = request?.Id; Attribute ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Attribute>(currentUser, "Attribute", request.Select); DocEntityAttribute entity = null; if (id.HasValue) { entity = DocEntityAttribute.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Attribute 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 Attribute Post(AttributeCopy request) { Attribute ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityAttribute.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 pAttributeName = entity.AttributeName; var pAttributeType = entity.AttributeType; var pInterval = entity.Interval; var pIsCharacteristic = entity.IsCharacteristic; var pIsOutcome = entity.IsOutcome; var pIsPositive = entity.IsPositive; var pUniqueKey = entity.UniqueKey; if (!DocTools.IsNullOrEmpty(pUniqueKey)) { pUniqueKey += " (Copy)"; } var pValueType = entity.ValueType; var copy = new DocEntityAttribute(ssn) { Hash = Guid.NewGuid() , AttributeName = pAttributeName , AttributeType = pAttributeType , Interval = pInterval , IsCharacteristic = pIsCharacteristic , IsOutcome = pIsOutcome , IsPositive = pIsPositive , UniqueKey = pUniqueKey , ValueType = pValueType }; copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }