private Characteristic GetCharacteristic(Characteristic request) { var id = request?.Id; Characteristic ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetVisibleFields <Characteristic>(currentUser, "Characteristic", request.VisibleFields); DocEntityCharacteristic entity = null; if (id.HasValue) { entity = DocEntityCharacteristic.GetCharacteristic(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Characteristic 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 Characteristic Post(CharacteristicCopy request) { Characteristic ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityCharacteristic.GetCharacteristic(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 pDocumentSets = entity.DocumentSets.ToList(); var pName = entity.Name; if (!DocTools.IsNullOrEmpty(pName)) { pName += " (Copy)"; } var pURI = entity.URI; if (!DocTools.IsNullOrEmpty(pURI)) { pURI += " (Copy)"; } #region Custom Before copyCharacteristic #endregion Custom Before copyCharacteristic var copy = new DocEntityCharacteristic(ssn) { Hash = Guid.NewGuid() , Name = pName , URI = pURI }; foreach (var item in pDocumentSets) { entity.DocumentSets.Add(item); } #region Custom After copyCharacteristic #endregion Custom After copyCharacteristic copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }