Exemple #1
0
        public void Delete(TherapeuticAreaSet request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityTherapeuticAreaSet.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No TherapeuticAreaSet 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.THERAPEUTICAREASET);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Exemple #2
0
        private TherapeuticAreaSet GetTherapeuticAreaSet(TherapeuticAreaSet request)
        {
            var id = request?.Id;
            TherapeuticAreaSet ret = null;
            var query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <TherapeuticAreaSet>(currentUser, "TherapeuticAreaSet", request.Select);

            DocEntityTherapeuticAreaSet entity = null;

            if (id.HasValue)
            {
                entity = DocEntityTherapeuticAreaSet.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No TherapeuticAreaSet 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);
        }
Exemple #3
0
        public TherapeuticAreaSetMapper()
        {
            CreateMap <DocEntitySet <DocEntityTherapeuticAreaSet>, List <Reference> >()
            .ConvertUsing(s => s.ToReferences());
            CreateMap <DocEntityTherapeuticAreaSet, Reference>()
            .ConstructUsing(s => null == s || !(s.Id > 0) ? null : s.ToReference());
            CreateMap <Reference, DocEntityTherapeuticAreaSet>()
            .ForMember(dest => dest.Id, opt => opt.Condition(src => null != src && src.Id > 0))
            .ConstructUsing(c => DocEntityTherapeuticAreaSet.Get(c));
            _EntityToDto = CreateMap <DocEntityTherapeuticAreaSet, TherapeuticAreaSet>()
                           .ForMember(dest => dest.Created, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <TherapeuticAreaSet>(c, "Created")))
                           .ForMember(dest => dest.Updated, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <TherapeuticAreaSet>(c, "Updated")))

                           .MaxDepth(2);
            _DtoToEntity = CreateMap <TherapeuticAreaSet, DocEntityTherapeuticAreaSet>()
                           .MaxDepth(2);
            ApplyCustomMaps();
        }
Exemple #4
0
        private Default _AssignValues(Default 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, "Default"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            Default ret = null;

            request = _InitAssignValues <Default>(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 <Default>(DocConstantModelName.DEFAULT, nameof(Default), request);

            //First, assign all the variables, do database lookups and conversions
            var pDiseaseState    = DocEntityDiseaseStateSet.Get(request.DiseaseState?.Id, true, Execute) ?? DocEntityDiseaseStateSet.Get(request.DiseaseStateId, true, Execute);
            var pRole            = DocEntityRole.Get(request.Role?.Id, true, Execute) ?? DocEntityRole.Get(request.RoleId, true, Execute);
            var pScope           = DocEntityScope.Get(request.Scope?.Id, true, Execute) ?? DocEntityScope.Get(request.ScopeId, true, Execute);
            var pTherapeuticArea = DocEntityTherapeuticAreaSet.Get(request.TherapeuticArea?.Id, true, Execute) ?? DocEntityTherapeuticAreaSet.Get(request.TherapeuticAreaId, true, Execute);
            var pArchived        = true == request.Archived;
            var pLocked          = request.Locked;

            var entity = InitEntity <DocEntityDefault, Default>(request, permission, session);

            if (AllowPatchValue <Default, bool>(request, DocConstantModelName.DEFAULT, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <Default, DocEntityDiseaseStateSet>(request, DocConstantModelName.DEFAULT, pDiseaseState, permission, nameof(request.DiseaseState), pDiseaseState != entity.DiseaseState))
            {
                entity.DiseaseState = pDiseaseState;
            }
            if (AllowPatchValue <Default, DocEntityRole>(request, DocConstantModelName.DEFAULT, pRole, permission, nameof(request.Role), pRole != entity.Role))
            {
                entity.Role = pRole;
            }
            if (AllowPatchValue <Default, DocEntityScope>(request, DocConstantModelName.DEFAULT, pScope, permission, nameof(request.Scope), pScope != entity.Scope))
            {
                entity.Scope = pScope;
            }
            if (AllowPatchValue <Default, DocEntityTherapeuticAreaSet>(request, DocConstantModelName.DEFAULT, pTherapeuticArea, permission, nameof(request.TherapeuticArea), pTherapeuticArea != entity.TherapeuticArea))
            {
                entity.TherapeuticArea = pTherapeuticArea;
            }
            if (request.Locked && AllowPatchValue <Default, bool>(request, DocConstantModelName.DEFAULT, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DEFAULT);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <Default>(currentUser, nameof(Default), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DEFAULT);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DEFAULT, cacheExpires);

            return(ret);
        }
Exemple #5
0
        public TherapeuticAreaSet Post(TherapeuticAreaSetCopy request)
        {
            TherapeuticAreaSet ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTherapeuticAreaSet.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 pClients             = entity.Clients.ToList();
                    var pConfidential        = entity.Confidential;
                    var pDivisions           = entity.Divisions.ToList();
                    var pDocuments           = entity.Documents.ToList();
                    var pDocumentSets        = entity.DocumentSets.ToList();
                    var pHistories           = entity.Histories.ToList();
                    var pLegacyDocumentSetId = entity.LegacyDocumentSetId;
                    var pName = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pOwner       = entity.Owner;
                    var pProjectTeam = entity.ProjectTeam;
                    var pScopes      = entity.Scopes.ToList();
                    var pSettings    = entity.Settings;
                    var pStats       = entity.Stats.ToList();
                    var pType        = entity.Type;
                    var pUsers       = entity.Users.ToList();
                    var copy         = new DocEntityTherapeuticAreaSet(ssn)
                    {
                        Hash                  = Guid.NewGuid()
                        , Confidential        = pConfidential
                        , LegacyDocumentSetId = pLegacyDocumentSetId
                        , Name                = pName
                        , Owner               = pOwner
                        , ProjectTeam         = pProjectTeam
                        , Settings            = pSettings
                        , Type                = pType
                    };
                    foreach (var item in pClients)
                    {
                        entity.Clients.Add(item);
                    }

                    foreach (var item in pDivisions)
                    {
                        entity.Divisions.Add(item);
                    }

                    foreach (var item in pDocuments)
                    {
                        entity.Documents.Add(item);
                    }

                    foreach (var item in pDocumentSets)
                    {
                        entity.DocumentSets.Add(item);
                    }

                    foreach (var item in pHistories)
                    {
                        entity.Histories.Add(item);
                    }

                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

                    foreach (var item in pStats)
                    {
                        entity.Stats.Add(item);
                    }

                    foreach (var item in pUsers)
                    {
                        entity.Users.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }