Esempio n. 1
0
        /// <summary>
        /// Ajusta el pais del dealer
        /// </summary>
        /// <param name="dealerCountry"></param>
        /// <returns></returns>
        internal String AjusCountrie(String dealerCountry)
        {
            String idCountrySystime = ConstantsSystimeDataAccess.ID_COUNTRY_UNKONOWN;//valor apra la ciudad desconocida

            using (DmsV1Entities dbErp = new DmsV1Entities(ParamsContract.ConectionStringErp))
            {
                dbErp.Database.CommandTimeout = 1000;
                y_paises countryDealer;

                if (!String.IsNullOrEmpty(dealerCountry))
                {
                    if (int.TryParse(dealerCountry, out int idCityCatalogDms))
                    {
                        countryDealer = dbErp.y_paises.FirstOrDefault(p => p.pais == dealerCountry);
                    }
                    else
                    {
                        countryDealer = dbErp.y_paises.FirstOrDefault(p => p.descripcion == dealerCountry);
                    }

                    if (!String.IsNullOrEmpty(countryDealer?.descripcion))
                    {
                        using (SystimedbEntities dbSystime = new SystimedbEntities(ParamsContract.ConectionStringSystime))
                        {
                            List <String> countries = dbSystime.AjustCountry(ParamsContract.Language, countryDealer.descripcion).ToList();
                            if (countries?.Count == 1)
                            {
                                idCountrySystime = countries[0];
                            }
                        }
                    }
                }
                return(idCountrySystime);
            }
        }
        internal bool DeleteNotificationSystime(int idNotificationsystime)
        {
            NotificationSystime entityDelete = null;

            using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
            {
                DataBase.Database.CommandTimeout = 2000;
                entityDelete = DataBase.NotificationSystime.FirstOrDefault(n => n.IdNotificationSystime == idNotificationsystime);
                if (entityDelete == null)
                {
                    return(true);
                }
                else if (entityDelete.IdNotificationSystime > 0)
                {
                    DataBase.NotificationSystime.Remove(entityDelete);
                    try
                    {
                        if (DataBase.SaveChanges() > 0)
                        {
                            return(true);
                        }
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var entry = ex.Entries.Single();
                        return(entry.State == EntityState.Deleted);
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Ajusta la ciduad del dealer a la ciudad de tipo sytime si coninciden en la informacion
        /// </summary>
        /// <param name="dealerCountry"></param>
        /// <returns></returns>
        internal int AjusCity(String idCityDealer, String idDealerState, String idDealerCountrie)
        {
            int idCitySystime = ConstantsSystimeDataAccess.ID_CITY_UNKOWN;//valor apra la ciudad desconocida

            using (DmsV1Entities dbErp = new DmsV1Entities(ParamsContract.ConectionStringErp))
            {
                dbErp.Database.CommandTimeout = 1000;

                y_ciudades      cityDealer     = null;
                y_paises        countrieDealer = null;
                y_departamentos stateDealer    = null;

                if (!String.IsNullOrEmpty(idCityDealer))
                {
                    ///Ajusta el paise
                    if (!String.IsNullOrEmpty(idDealerCountrie))
                    {
                        if ((int.TryParse(idDealerCountrie, out int idCountry)))
                        {
                            countrieDealer = dbErp.y_paises.FirstOrDefault(p => p.pais == idDealerCountrie);
                        }
                        else
                        {
                            countrieDealer = dbErp.y_paises.FirstOrDefault(p => p.descripcion.Contains(idDealerCountrie));
                        }
                    }

                    ///Ajusta el departamento
                    if (!String.IsNullOrEmpty(idDealerState))
                    {
                        if ((int.TryParse(idDealerState, out int idState)) && countrieDealer != null)
                        {
                            stateDealer = dbErp.y_departamentos.FirstOrDefault(p => p.departamento == idDealerState && p.pais == countrieDealer.pais);
                        }
                        else if (countrieDealer != null)
                        {
                            stateDealer = dbErp.y_departamentos.FirstOrDefault(p => p.descripcion.Contains(idDealerState) && p.pais == countrieDealer.pais);
                        }


                        //Busca el valor asi no se halla encontrado su integrisdad refeesncial
                        if (stateDealer == null)
                        {
                            if ((int.TryParse(idDealerState, out int idStates)))
                            {
                                stateDealer = dbErp.y_departamentos.FirstOrDefault(p => p.departamento == idDealerState);
                            }
                            else
                            {
                                stateDealer = dbErp.y_departamentos.FirstOrDefault(p => p.descripcion.Contains(idDealerState));
                            }
                        }
                    }
 internal Boolean DeleteNotificationSystimeGrouup(String jsonKyes, String tableName, String eventTable, DateTime dateTimeLimit)
 {
     using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
     {
         DataBase.Database.CommandTimeout = 4000;
         if (DataBase.Database.ExecuteSqlCommand("DELETE FROM NotificationSystime WHERE TableName = {0} AND  JsonKeys = {1} AND EventTable={2} AND CreateAt<{3}", tableName, jsonKyes, eventTable, dateTimeLimit) > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Metoto encargado de obtener Customer a partir
        /// </summary>
        /// <param name="idCustomer"></param>
        /// <returns></returns>
        internal Customers GetCustomer(String jsonKeys)
        {
            CustomerKeys customerKeys = JsonConvert.DeserializeObject <CustomerKeys>(jsonKeys);

            if (customerKeys != null && decimal.TryParse(customerKeys?.IdCustomer, out decimal nit))
            {
                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    DataBase.Database.CommandTimeout = 1000;
                    terceros customerErp = DataBase.terceros.FirstOrDefault(d => d.nit == nit);
                    return(ParseCustomer(customerErp));
                }
            }
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Metoto encargado de consutlar el dealerRepresentative en el erp
        /// </summary>
        /// <param name="idDealer"></param>
        /// <param name="idDealerShop"></param>
        /// <returns></returns>
        internal Workers GetWorker(String jsonKeys, out List <Tuple <Type, String> > paramsAditional)
        {
            paramsAditional = null;
            String          DealerShop = null;
            Boolean         isDealerRepresentatives = false;
            String          activityWorker          = "";
            Boolean?        isActive   = true;
            WorkerKeysDmsV1 workerKeys = JsonConvert.DeserializeObject <WorkerKeysDmsV1>(jsonKeys);

            if (workerKeys != null && !String.IsNullOrEmpty(workerKeys?.IdWorker))
            {
                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    DataBase.Database.CommandTimeout = 1000;
                    if (int.TryParse(workerKeys.IdWorker, out int id))
                    {
                        tall_operarios operarioErp = DataBase.tall_operarios.FirstOrDefault(w => w.nit == id);
                        terceros       workerErp   = null;
                        if (operarioErp != null)
                        {
                            activityWorker = operarioErp.actividad;
                            isActive       = operarioErp.activo;
                            //Si esto ocurre es operario
                            workerErp  = operarioErp.terceros;
                            DealerShop = operarioErp.bodega?.ToString();
                        }
                        else
                        {
                            isDealerRepresentatives = true;
                            workerErp = DataBase.terceros.FirstOrDefault(w => w.nit == id);
                        }


                        if (String.IsNullOrEmpty(DealerShop))
                        {
                            DealerShop = workerKeys.IdDealerShopWorkOrder;
                        }

                        if (workerErp != null)
                        {
                            return(ParseWorker(workerErp, DealerShop, isDealerRepresentatives, activityWorker, out paramsAditional, isActive));
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Metoto encargado de obtener la compañia de seguros
        /// </summary>
        /// <param name="tinInsuranceCompany"></param>
        /// <returns></returns>
        internal CloudCatalogInsuranceCompanies GetInsuranceCompany(String jsonKeys)
        {
            InsuranceComnayKeysDmsV1 InsuranceCompanyKeys = JsonConvert.DeserializeObject <InsuranceComnayKeysDmsV1>(jsonKeys);

            if (InsuranceCompanyKeys != null && decimal.TryParse(InsuranceCompanyKeys?.Tin, out decimal nit))
            {
                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    DataBase.Database.CommandTimeout = 1000;
                    terceros InsuranceCompanyErp = DataBase.terceros.FirstOrDefault(i => i.nit == nit);
                    if (InsuranceCompanyErp != null)
                    {
                        return(ParsheInsuranceCompany(InsuranceCompanyErp));
                    }
                }
            }
            return(null);
        }
Esempio n. 8
0
        /// <summary>
        /// Meotodo encargado de consultar la bodega del erp
        /// </summary>
        /// <param name="idShop"></param>
        /// <returns></returns>
        internal CloudCatalogDealerShops GetDealerShop(String jsonKeys)
        {
            DelaerShopKeysDmsV1 DealerShopKeys = JsonConvert.DeserializeObject <DelaerShopKeysDmsV1>(jsonKeys);

            if (DealerShopKeys != null && int.TryParse(DealerShopKeys?.IdShop, out int id))
            {
                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    DataBase.Database.CommandTimeout = 1000;
                    bodegas dealerShopErp = DataBase.bodegas.FirstOrDefault(b => b.id == id);
                    if (dealerShopErp != null)
                    {
                        return(ParseDealerShop(dealerShopErp));
                    }
                }
            }
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// Metoto encargado de convertir un vehiculo del erp a systime
        /// </summary>
        /// <param name="vehicleErp"></param>
        /// <returns></returns>
        internal Vehicles ParseVehicle(referencias_imp vehicleErp, out List <Tuple <Type, string> > paramsAditional)
        {
            paramsAditional = null;
            if (vehicleErp != null)
            {
                long.TryParse(vehicleErp?.nit_comprador?.ToString() ?? "00", out long idcustomer);
                String modelDealer = String.Empty;

                String countryDescription = null;

                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    String paisErp = DataBase.y_ciudades.FirstOrDefault(c => c.ciudad == vehicleErp.ciudad_placa)?.pais?.ToString();
                    countryDescription = DataBase.y_paises.FirstOrDefault(p => p.pais == paisErp)?.descripcion?.ToString();
                    modelDealer        = DataBase.vh_modelo_taller.FirstOrDefault(tm => tm.modelo_taller == vehicleErp.modelo_taller)?.descripcion?.ToString();
                }

                paramsAditional = new List <Tuple <Type, string> >
                {
                    new Tuple <Type, string>(typeof(CloudCatalogInsuranceCompanies), JsonConvert.SerializeObject(new InsuranceComnayKeysDmsV1()
                    {
                        Tin = vehicleErp?.nit_aseguradora?.ToString()
                    })),
                };
                return(new Vehicles()
                {
                    IdVinNumber = vehicleErp.serie,
                    Plate = new ToolsDmsV1(ParamsContract).AdjustPlate(vehicleErp.placa),
                    DealerVehicleModel = modelDealer,
                    ModelYear = vehicleErp.modelo_ano == null ? 0 : Convert.ToInt32(vehicleErp.modelo_ano),
                    Color = vehicleErp.color,
                    LastMileage = vehicleErp.kilometraje == null ? 0 : Convert.ToInt32(vehicleErp.kilometraje),
                    IdCity = new ToolsDmsV1(ParamsContract).AjusCity(vehicleErp.ciudad_placa, null, null),
                    IdVehicleModel = new ToolsDmsV1(ParamsContract).AjustModel(vehicleErp.id_modano, modelDealer),
                    DealerCity = vehicleErp.ciudad_placa,
                    IdCustomerOwner = idcustomer,
                    IdCountry = new ToolsDmsV1(ParamsContract).AjusCountrie(countryDescription),
                    SaleGuaranteeAt = vehicleErp.fecha_fin_garantia,
                    GuaranteedSaleDistanceTraveled = vehicleErp.Km_Garantia
                });
            }
            return(null);
        }
Esempio n. 10
0
        /// <summary>
        /// Metoto encargado de consultar un vehiculo en el erp
        /// </summary>
        /// <param name="idVinVehicle"></param>
        /// <returns></returns>
        internal Vehicles GetVehicle(String jsonKeys, out List <Tuple <Type, string> > paramsAditional)
        {
            paramsAditional = null;
            VehiclesKeysDmsV1 vehicle = JsonConvert.DeserializeObject <VehiclesKeysDmsV1>(jsonKeys);

            if (vehicle != null && !String.IsNullOrEmpty(vehicle?.VinNumber))
            {
                using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
                {
                    DataBase.Database.CommandTimeout = 1000;
                    referencias_imp vehicleErp = DataBase.referencias_imp.FirstOrDefault(v => v.codigo == vehicle.VinNumber);
                    if (vehicleErp != null)
                    {
                        return(ParseVehicle(vehicleErp, out paramsAditional));
                    }
                }
            }
            return(null);
        }
        internal List <NotificationSystimeIntegrate> GetAllNotification()
        {
            List <NotificationSystimeIntegrate> listNotificationIntegrate = new List <NotificationSystimeIntegrate>();

            using (DmsV1Entities DataBase = new DmsV1Entities(ConectionStringErp))
            {
                DataBase.Database.CommandTimeout = 4000;
                DataBase.NotificationSystime.ToList().ForEach(n => {
                    listNotificationIntegrate.Add(new NotificationSystimeIntegrate()
                    {
                        IdNotification = n.IdNotificationSystime.ToString(),
                        TableName      = n.TableName,
                        JsonKeys       = n.JsonKeys,
                        Event          = n.EventTable,
                        CreatedAt      = n.CreateAt
                    });
                });
                return(listNotificationIntegrate);
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Cosntructor de la clase
 /// </summary>
 internal WorkOrderDmsV1(ParamsContract paramsContract)
 {
     ParamsContract = paramsContract;
     DataBase       = new DmsV1Entities(paramsContract.ConectionStringErp);
 }