Exemplo n.º 1
0
        private LocaleLookup GetLocaleLookup(LocaleLookup request)
        {
            var          id    = request?.Id;
            LocaleLookup ret   = null;
            var          query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityLocaleLookup entity = null;

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

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLocaleLookup.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 pData      = entity.Data;
                    var pIpAddress = entity.IpAddress;
                    if (!DocTools.IsNullOrEmpty(pIpAddress))
                    {
                        pIpAddress += " (Copy)";
                    }
                    var pLocale = entity.Locale;
                    var copy    = new DocEntityLocaleLookup(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , Data      = pData
                        , IpAddress = pIpAddress
                        , Locale    = pLocale
                    };

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