コード例 #1
0
        public static EtiAplicacao GetNewEtiAplicacao(EtiAppAuthentication authentication)
        {
            EtiAplicacao etiApp = new EtiAplicacao();

            try
            {
                if (!etiApp.InitializeEtiApp(EtiConstantes.cAplicBackOffice, authentication.SQLServerName, authentication.SystemDatabase, authentication.SQLUser, authentication.SQLPassword, string.Empty, string.Empty, string.Empty, string.Empty, authentication.serviceAddress, true, string.Empty))
                {
                    throw new Exception("Ocorreu um erro a inicializar etiAplicacao...");
                }

                EtiAplicacao.LoginResult result;
                if ((result = etiApp.Login(authentication.Login, authentication.Password)) != EtiAplicacao.LoginResult.Ok)
                {
                    throw new Exception(result == EtiAplicacao.LoginResult.InvalidUser ? "Invalid user..." : "Wrong user or password...");
                }

                if (!etiApp.OpenEmpresa(authentication.Company))
                {
                    throw new Exception("Empresa inválida ...");
                }

                if (!etiApp.OpenExercicio(authentication.FiscalYearCode))
                {
                    throw new Exception("Exercício inválido...");
                }

                if (!etiApp.OpenSeccao(authentication.SectionCode))
                {
                    throw new Exception("Seção inválida...");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(etiApp);
        }
コード例 #2
0
        public IHttpActionResult SaveAttachment([FromBody] string base64Document)
        {
            try
            {
                Eticadata.RiaServices.AuthenticationService authSvc = new RiaServices.AuthenticationService();
                string       strCustomData = Eticadata.LoginData.GetCustomData("(LocalDB)\\MSSQLLocalDB", "sistema", string.Empty, true, true, "pt-PT");
                EtiAplicacao etiApp        = new EtiAplicacao();

                var myEtiUser = authSvc.Login("demo", "demo", false, strCustomData);
                if (myEtiUser != null)
                {
                    switch (myEtiUser.loginResult)
                    {
                    case 0:
                        etiApp = Eti.Aplicacao;
                        break;

                    case 2:
                        throw new Exception("The user does not exists!");

                    case 3:
                        throw new Exception("The user is inactive!");

                    default:
                        throw new Exception("The user does not exists!");
                    }
                }

                bool initResult = etiApp.OpenEmpresa("D18");

                if (!initResult)
                {
                    throw new Exception("OpenCompany: Não foi possivel efetuar a autenticação no ERP.");
                }

                initResult = etiApp.OpenExercicio("EX 2018");

                if (!initResult)
                {
                    throw new Exception("OpenFiscalYear: Não foi possivel efetuar a autenticação no ERP.");
                }

                initResult = etiApp.OpenSeccao("SEC1");

                if (!initResult)
                {
                    throw new Exception("OpenSection: Não foi possivel efetuar a autenticação no ERP.");
                }

                RiaServices.Attachments.Services.AnexosDigitaisService attachSrv = new RiaServices.Attachments.Services.AnexosDigitaisService();

                attachSrv.UpdateAnexoDigital(new RiaServices.Attachments.Models.AnexoDigital()
                {
                    Entidades = new System.Data.Entity.Core.Objects.DataClasses.EntityCollection <RiaServices.Attachments.Models.Entidade>()
                    {
                        new RiaServices.Attachments.Models.Entidade()
                        {
                            TipoEntidade = (int)TpEntidade.Cliente,
                            Chave1       = "1"
                        }
                    },
                    TipoDocumentacao = "DOC",
                    CodDocumentacao  = "BI",
                    DataEmissao      = DateTime.Now,
                    CodSituacao      = 0,
                    DataSituacao     = DateTime.Now,
                    Ficheiro         = Convert.FromBase64String(base64Document),
                    Ref   = "0001/2018",
                    Local = "SEDE",
                    Obs   = "Documento anexado ao cliente 1"
                });

                return(Ok());
            } catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }