Ejemplo n.º 1
0
        private Client GetClient(Client request)
        {
            var    id    = request?.Id;
            Client ret   = null;
            var    query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityClient entity = null;

            if (id.HasValue)
            {
                entity = DocEntityClient.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No Client 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);
        }
Ejemplo n.º 2
0
        public Client Post(ClientCopy request)
        {
            Client ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityClient.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 pDefaultLocale = entity.DefaultLocale;
                    var pDivisions     = entity.Divisions.ToList();
                    var pDocumentSets  = entity.DocumentSets.ToList();
                    var pName          = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pProjects            = entity.Projects.ToList();
                    var pRole                = entity.Role;
                    var pSalesforceAccountId = entity.SalesforceAccountId;
                    if (!DocTools.IsNullOrEmpty(pSalesforceAccountId))
                    {
                        pSalesforceAccountId += " (Copy)";
                    }
                    var pScopes   = entity.Scopes.ToList();
                    var pSettings = entity.Settings;
                    var copy      = new DocEntityClient(ssn)
                    {
                        Hash                  = Guid.NewGuid()
                        , DefaultLocale       = pDefaultLocale
                        , Name                = pName
                        , Role                = pRole
                        , SalesforceAccountId = pSalesforceAccountId
                        , Settings            = pSettings
                    };
                    foreach (var item in pDivisions)
                    {
                        entity.Divisions.Add(item);
                    }

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

                    foreach (var item in pProjects)
                    {
                        entity.Projects.Add(item);
                    }

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

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