public static FornecedorDetailsViewModel MapVendorNAVToVendorModel(WSVendorNAV.WSVendor VendorNAV)
        {
            FornecedorDetailsViewModel VendorVM = new FornecedorDetailsViewModel();

            if (VendorNAV != null)
            {
                VendorVM.No                 = VendorNAV.No;
                VendorVM.Name               = VendorNAV.Name;
                VendorVM.FullAddress        = VendorNAV.Address + " " + VendorNAV.Address_2;
                VendorVM.PostCode           = VendorNAV.Post_Code;
                VendorVM.City               = VendorNAV.City;
                VendorVM.Country            = VendorNAV.Country_Region_Code;
                VendorVM.Phone              = VendorNAV.Phone_No;
                VendorVM.Email              = VendorNAV.E_Mail;
                VendorVM.Fax                = VendorNAV.Fax_No;
                VendorVM.HomePage           = VendorNAV.Home_Page;
                VendorVM.VATRegistrationNo  = VendorNAV.VAT_Registration_No;
                VendorVM.PaymentTermsCode   = VendorNAV.Payment_Terms_Code;
                VendorVM.PaymentMethodCode  = VendorNAV.Payment_Method_Code;
                VendorVM.NoClienteAssociado = VendorNAV.No_Cliente_Assoc;
                VendorVM.Blocked            = (int)VendorNAV.Blocked;
                VendorVM.Address            = VendorNAV.Address;
                VendorVM.Address_2          = VendorNAV.Address_2;
                VendorVM.Distrito           = VendorNAV.County;
                VendorVM.Criticidade        = (int)VendorNAV.Criticidade;
                VendorVM.Observacoes        = VendorNAV.Observacoes;
            }

            return(VendorVM);
        }
        public static WSVendorNAV.WSVendor MapVendorModelToVendorNAV(FornecedorDetailsViewModel VendorModel)
        {
            WSVendorNAV.WSVendor VendorNAV = new WSVendorNAV.WSVendor();
            if (VendorModel != null)
            {
                VendorNAV.No                  = VendorModel.No;
                VendorNAV.Name                = VendorModel.Name;
                VendorNAV.Post_Code           = VendorModel.PostCode;
                VendorNAV.City                = VendorModel.City;
                VendorNAV.Country_Region_Code = VendorModel.Country;
                VendorNAV.Phone_No            = VendorModel.Phone;
                VendorNAV.E_Mail              = VendorModel.Email;
                VendorNAV.Fax_No              = VendorModel.Fax;
                VendorNAV.Home_Page           = VendorModel.HomePage;
                VendorNAV.VAT_Registration_No = VendorModel.VATRegistrationNo;
                VendorNAV.Payment_Terms_Code  = VendorModel.PaymentTermsCode;
                VendorNAV.Payment_Method_Code = VendorModel.PaymentMethodCode;
                VendorNAV.No_Cliente_Assoc    = VendorModel.NoClienteAssociado;
                VendorNAV.Blocked             = (Blocked)VendorModel.Blocked;
                VendorNAV.Address             = VendorModel.Address;
                VendorNAV.Address_2           = VendorModel.Address_2;
                VendorNAV.County              = VendorModel.Distrito;
                VendorNAV.Criticidade         = (Criticidade)VendorModel.Criticidade;
                VendorNAV.Observacoes         = VendorModel.Observacoes;
            }

            return(VendorNAV);
        }
Esempio n. 3
0
        public JsonResult Delete([FromBody] FornecedorDetailsViewModel data)
        {
            if (data != null && data.No != null)
            {
                data.Utilizador_Alteracao_eSUCH = User.Identity.Name;
                var deleteVendorTask = WSVendorService.DeleteAsync(data.No, _configws);
                try
                {
                    deleteVendorTask.Wait();
                }
                catch (Exception ex)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro a apagar o fornecedor no NAV.";
                    data.eMessages.Add(new TraceInformation(TraceType.Error, ex.Message));
                    return(Json(data));
                }

                var result = deleteVendorTask.Result;
                if (result != null)
                {
                    return(Json(new ErrorHandler()
                    {
                        eReasonCode = 0,
                        eMessage = "Fornecedor removido com sucesso."
                    }));
                }
            }
            return(Json(false));
        }
Esempio n. 4
0
        public JsonResult Update([FromBody] FornecedorDetailsViewModel data)
        {
            if (data != null)
            {
                data.Utilizador_Alteracao_eSUCH = User.Identity.Name;
                var updateVendorTask = WSVendorService.UpdateAsync(data, _configws);
                try
                {
                    updateVendorTask.Wait();
                }
                catch (Exception ex)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro ao atualizar o fornecedor no NAV.";
                    data.eMessages.Add(new TraceInformation(TraceType.Error, ex.Message));
                    return(Json(data));
                }

                var result = updateVendorTask.Result;
                if (result == null)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro ao atualizar o fornecedor no NAV.";
                    return(Json(data));
                }

                var vendor = WSVendorService.MapVendorNAVToVendorModel(result.WSVendor);
                if (vendor != null)
                {
                    vendor.eReasonCode = 1;
                    return(Json(vendor));
                }
            }
            return(Json(false));
        }
Esempio n. 5
0
        public JsonResult GetDetails([FromBody] FornecedorDetailsViewModel data)
        {
            if (data != null && data.No != null)
            {
                var getVendorTask = WSVendorService.GetByNoAsync(data.No, _configws);
                try
                {
                    getVendorTask.Wait();
                }
                catch (Exception ex)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro a obter o fornecedor no NAV.";
                    data.eMessages.Add(new TraceInformation(TraceType.Error, ex.Message));
                    return(Json(data));
                }

                FornecedorDetailsViewModel vendor = getVendorTask.Result;
                if (vendor != null)
                {
                    return(Json(vendor));
                }
            }
            return(Json(false));
        }
        public static async Task <WSVendorNAV.Update_Result> UpdateAsync(FornecedorDetailsViewModel vendor, NAVWSConfigurations WSConfigurations)
        {
            if (vendor == null)
            {
                throw new ArgumentNullException("vendor");
            }


            WSVendorNAV.Update navUpdate = new WSVendorNAV.Update()
            {
                WSVendor = MapVendorModelToVendorNAV(vendor)
            };

            //Configure NAV Vendor
            EndpointAddress ws_URL = new EndpointAddress(WSConfigurations.WS_Vendor_URL.Replace("Company", WSConfigurations.WS_User_Company));

            WSVendorNAV.WSVendor_PortClient ws_Vendor = new WSVendorNAV.WSVendor_PortClient(navWSBinding, ws_URL);
            ws_Vendor.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
            ws_Vendor.ClientCredentials.Windows.ClientCredential          = new NetworkCredential(WSConfigurations.WS_User_Login, WSConfigurations.WS_User_Password, WSConfigurations.WS_User_Domain);

            WSVendorNAV.Read_Result resultRead = await ws_Vendor.ReadAsync(navUpdate.WSVendor.No);

            navUpdate.WSVendor.Key = resultRead.WSVendor.Key;

            try
            {
                navUpdate.WSVendor.Utilizador_Alteracao_eSUCH = vendor.Utilizador_Alteracao_eSUCH;

                navUpdate.WSVendor.BlockedSpecified = true;
                navUpdate.WSVendor.Bloqueado_Falta_PagamentoSpecified = true;
                navUpdate.WSVendor.Bloqueado_UrgenteSpecified         = true;
                navUpdate.WSVendor.CertificaçãoSpecified      = true;
                navUpdate.WSVendor.ClassificaçãoSpecified     = true;
                navUpdate.WSVendor.CriticidadeSpecified       = true;
                navUpdate.WSVendor.Interface_ComprasSpecified = true;
                navUpdate.WSVendor.PontuaçãoSpecified         = true;
                navUpdate.WSVendor.PreferencialSpecified      = true;

                WSVendorNAV.Update_Result result = await ws_Vendor.UpdateAsync(navUpdate);

                return(result);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 7
0
        public JsonResult Create([FromBody] FornecedorDetailsViewModel data)
        {
            if (data != null)
            {
                if (string.IsNullOrEmpty(data.No))
                {
                    data.No = "";
                }
                if (string.IsNullOrEmpty(data.Name))
                {
                    data.Name = "";
                }
                if (string.IsNullOrEmpty(data.PostCode))
                {
                    data.PostCode = "";
                }
                if (string.IsNullOrEmpty(data.City))
                {
                    data.City = "";
                }
                if (string.IsNullOrEmpty(data.Country))
                {
                    data.Country = "";
                }
                if (string.IsNullOrEmpty(data.Phone))
                {
                    data.Phone = "";
                }
                if (string.IsNullOrEmpty(data.Email))
                {
                    data.Email = "";
                }
                if (string.IsNullOrEmpty(data.Fax))
                {
                    data.Fax = "";
                }
                if (string.IsNullOrEmpty(data.HomePage))
                {
                    data.HomePage = "";
                }
                if (string.IsNullOrEmpty(data.VATRegistrationNo))
                {
                    data.VATRegistrationNo = "";
                }
                if (string.IsNullOrEmpty(data.PaymentTermsCode))
                {
                    data.PaymentTermsCode = "";
                }
                if (string.IsNullOrEmpty(data.PaymentMethodCode))
                {
                    data.PaymentMethodCode = "";
                }
                if (string.IsNullOrEmpty(data.NoClienteAssociado))
                {
                    data.NoClienteAssociado = "";
                }
                if (data.Blocked == null)
                {
                    data.Blocked = 0;
                }
                if (string.IsNullOrEmpty(data.Address))
                {
                    data.Address = "";
                }
                if (string.IsNullOrEmpty(data.Address_2))
                {
                    data.Address_2 = "";
                }
                if (string.IsNullOrEmpty(data.Distrito))
                {
                    data.Distrito = "";
                }
                if (data.Criticidade == null)
                {
                    data.Criticidade = 0;
                }
                if (string.IsNullOrEmpty(data.Observacoes))
                {
                    data.Observacoes = "";
                }

                data.Utilizador_Alteracao_eSUCH = User.Identity.Name;
                var createVendorTask = WSVendorService.CreateAsync(data, _configws);
                try
                {
                    createVendorTask.Wait();
                }
                catch (Exception ex)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro ao criar o fornecedor no NAV.";
                    data.eMessages.Add(new TraceInformation(TraceType.Error, ex.Message));
                    return(Json(data));
                }

                var result = createVendorTask.Result;
                if (result == null)
                {
                    data.eReasonCode = 3;
                    data.eMessage    = "Ocorreu um erro ao criar o fornecedor no NAV.";
                    return(Json(data));
                }

                data.eReasonCode = 1;

                var vendor = WSVendorService.MapVendorNAVToVendorModel(result.WSVendor);

                if (vendor != null)
                {
                    //SUCESSO
                    vendor.eReasonCode = 1;

                    //Envio de email
                    ConfiguracaoParametros Parametro = DBConfiguracaoParametros.GetByParametro("AddFornecedorEmail");
                    ConfigUtilizadores     UserEmail = DBUserConfigurations.GetById(User.Identity.Name);

                    if (Parametro != null && !string.IsNullOrEmpty(Parametro.Valor))
                    {
                        SendEmailApprovals Email = new SendEmailApprovals();

                        var    path_tmp       = Path.Combine(_generalConfig.FileUploadFolder + "Fornecedores\\tmp\\", data.NomeAnexo);
                        string FileName_Final = data.NomeAnexo.Replace("FORNECEDOR", vendor.No);
                        var    path_final     = Path.Combine(_generalConfig.FileUploadFolder + "Fornecedores\\", FileName_Final);

                        FileStream file_tmp   = new FileStream(path_tmp, FileMode.Open);
                        FileStream file_final = new FileStream(path_final, FileMode.CreateNew);

                        file_tmp.CopyTo(file_final);

                        file_tmp.Dispose();
                        file_final.Dispose();

                        System.IO.File.Delete(path_tmp);

                        Anexos newfile = new Anexos();
                        newfile.NºOrigem          = vendor.No;
                        newfile.UrlAnexo          = FileName_Final;
                        newfile.TipoOrigem        = TipoOrigemAnexos.Fornecedores;
                        newfile.DataHoraCriação   = DateTime.Now;
                        newfile.UtilizadorCriação = User.Identity.Name;

                        Email.DisplayName = "e-SUCH - Fornecedor";
                        Email.From        = "*****@*****.**";
                        Email.To.Add(Parametro.Valor);
                        Email.BCC.Add("*****@*****.**");
                        Email.BCC.Add("*****@*****.**");
                        Email.Subject    = "e-SUCH - Novo Fornecedor";
                        Email.Body       = MakeEmailBodyContent("Criado o Fornecedor:  " + vendor.No + " - " + vendor.Name, UserEmail.Nome);
                        Email.Anexo      = path_final;
                        Email.IsBodyHtml = true;

                        Email.SendEmail_Simple();
                    }

                    return(Json(vendor));
                }
            }
            return(Json(data));
        }