public void Delete(LookupCategory request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityLookupCategory.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No LookupCategory 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.LOOKUPCATEGORY); DocCacheClient.RemoveById(request.Id); }); } }
public override void Setup() { _pathwayComponentGrade = LookupCategory.PathwayComponentGrade; _tokenServiceClient = Substitute.For <ITokenServiceClient>(); _configuration = new ResultsAndCertificationConfiguration { ResultsAndCertificationInternalApiSettings = new ResultsAndCertificationInternalApiSettings { Uri = "http://tlevel.api.com" } }; _mockHttpResult = new List <LookupData> { new LookupData { Id = 1, Code = "C1", Value = "V1" }, new LookupData { Id = 2, Code = "C2", Value = "V2" }, new LookupData { Id = 3, Code = "C3", Value = "V3" }, }; }
private LookupCategory GetLookupCategory(LookupCategory request) { var id = request?.Id; LookupCategory ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <LookupCategory>(currentUser, "LookupCategory", request.Select); DocEntityLookupCategory entity = null; if (id.HasValue) { entity = DocEntityLookupCategory.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No LookupCategory 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 LookupCategory Post(LookupCategory request) { if (request == null) { throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null."); } request.Select = request.Select ?? new List <string>(); LookupCategory ret = null; using (Execute) { Execute.Run(ssn => { if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "LookupCategory")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } ret = _AssignValues(request, DocConstantPermission.ADD, ssn); }); } return(ret); }
public async Task <IEnumerable <LookupData> > GetLookupDataAsync(LookupCategory lookupCategory) { var lookupData = await _tlLookupRepository.GetManyAsync(x => x.IsActive && x.Category == lookupCategory.ToString()) .OrderBy(x => x.SortOrder).ToListAsync(); return(_mapper.Map <IEnumerable <LookupData> >(lookupData)); }
/// <summary> /// Gets the category. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public LookupCategory GetCategory(string id) { LookupCategory lkup = new LookupCategory(); using (ISession session = CreateSession()) { lkup = session.Get <LookupCategory>(id); } return(lkup); }
public LookupCategory Post(LookupCategoryCopy request) { LookupCategory ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityLookupCategory.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 pCategory = entity.Category; if (!DocTools.IsNullOrEmpty(pCategory)) { pCategory += " (Copy)"; } var pEnum = entity.Enum; var pLookups = entity.Lookups.ToList(); var pParentCategory = entity.ParentCategory; var copy = new DocEntityLookupCategory(ssn) { Hash = Guid.NewGuid() , Category = pCategory , Enum = pEnum , ParentCategory = pParentCategory }; foreach (var item in pLookups) { entity.Lookups.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }
public LookupCategory Patch(LookupCategory request) { if (true != (request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the LookupCategory to patch."); } request.Select = request.Select ?? new List <string>(); LookupCategory ret = null; using (Execute) { Execute.Run(ssn => { ret = _AssignValues(request, DocConstantPermission.EDIT, ssn); }); } return(ret); }
public async Task <IList <LookupData> > GetLookupDataAsync(LookupCategory pathwayComponentGrade) { var requestUri = string.Format(ApiConstants.GetLookupDataUri, (int)pathwayComponentGrade); return(await GetAsync <IList <LookupData> >(requestUri)); }
public async Task <IEnumerable <LookupData> > GetLookupDataAsync(LookupCategory lookupCategory) { return(await _commonService.GetLookupDataAsync(lookupCategory)); }
public LookupCategory Put(LookupCategory request) { return(Patch(request)); }
private LookupCategory _AssignValues(LookupCategory request, DocConstantPermission permission, Session session) { if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No record"); } if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "LookupCategory")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); LookupCategory ret = null; request = _InitAssignValues <LookupCategory>(request, permission, session); //In case init assign handles create for us, return it if (permission == DocConstantPermission.ADD && request.Id > 0) { return(request); } var cacheKey = GetApiCacheKey <LookupCategory>(DocConstantModelName.LOOKUPCATEGORY, nameof(LookupCategory), request); //First, assign all the variables, do database lookups and conversions var pCategory = request.Category; var pEnum = DocEntityLookupTableEnum.Get(request.Enum); var pLookups = GetVariable <Reference>(request, nameof(request.Lookups), request.Lookups?.ToList(), request.LookupsIds?.ToList()); var pParentCategory = DocEntityLookupCategory.Get(request.ParentCategory?.Id, true, Execute) ?? DocEntityLookupCategory.Get(request.ParentCategoryId, true, Execute); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityLookupCategory, LookupCategory>(request, permission, session); if (AllowPatchValue <LookupCategory, bool>(request, DocConstantModelName.LOOKUPCATEGORY, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <LookupCategory, string>(request, DocConstantModelName.LOOKUPCATEGORY, pCategory, permission, nameof(request.Category), pCategory != entity.Category)) { entity.Category = pCategory; } if (AllowPatchValue <LookupCategory, DocEntityLookupTableEnum>(request, DocConstantModelName.LOOKUPCATEGORY, pEnum, permission, nameof(request.Enum), pEnum != entity.Enum)) { entity.Enum = pEnum; } if (AllowPatchValue <LookupCategory, DocEntityLookupCategory>(request, DocConstantModelName.LOOKUPCATEGORY, pParentCategory, permission, nameof(request.ParentCategory), pParentCategory != entity.ParentCategory)) { entity.ParentCategory = pParentCategory; } if (request.Locked && AllowPatchValue <LookupCategory, bool>(request, DocConstantModelName.LOOKUPCATEGORY, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <LookupCategory, DocEntityLookupCategory, Reference, DocEntityLookupTable>(request, entity, pLookups, permission, nameof(request.Lookups))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.LOOKUPCATEGORY); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <LookupCategory>(currentUser, nameof(LookupCategory), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.LOOKUPCATEGORY); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.LOOKUPCATEGORY, cacheExpires); return(ret); }
public object Get(LookupCategory request) => GetEntityWithCache <LookupCategory>(DocConstantModelName.LOOKUPCATEGORY, request, GetLookupCategory);