Exemplo n.º 1
0
        // Enviar sincronización de números al servidor
        public bool syncDrawType_LocalToServer()
        {
            bool successProcess = true;
            LotteryDrawTypeRepository  drawTypeRepository = new LotteryDrawTypeRepository();
            List <LDT_LotteryDrawType> unsynDrawTypeList  = drawTypeRepository.findUnsynTypes();

            // Sincronizar a servidor si existen elementos pendientes en cliente
            if (unsynDrawTypeList.Count > 0)
            {
                // Crear JsonArray
                var jsonObjectArray = new dynamic[unsynDrawTypeList.Count()];
                for (int i = 0; i < unsynDrawTypeList.Count(); i++)
                {
                    // Crear objeto json
                    var jsonObject = new
                    {
                        id          = unsynDrawTypeList[i].LDT_Id,
                        code        = unsynDrawTypeList[i].LDT_Code,
                        displayName = unsynDrawTypeList[i].LDT_DisplayName,
                        description = unsynDrawTypeList[i].LDT_Description
                    };
                    // Agregar el objeto al array
                    jsonObjectArray[i] = jsonObject;
                }
                var jsonNumberArray = new { items = jsonObjectArray };
                //Console.WriteLine(JsonConvert.SerializeObject(jsonNumberArray));
                ServerConnectionService connection     = new ServerConnectionService();
                ServiceResponseResult   responseResult = connection.sendDrawTypeToService(jsonNumberArray);
                string codeSectionDetail = MethodBase.GetCurrentMethod().DeclaringType.Name + ": " + MethodBase.GetCurrentMethod().Name;
                successProcess = this.isValidResponse(responseResult, codeSectionDetail);
                // Validar resultado de la sincronización
                if (successProcess)
                {
                    // Si el resultado del proceso es exitoso, cambiar estado a sincronizado
                    drawTypeRepository.changeStates(unsynDrawTypeList, SystemConstants.SYNC_STATUS_COMPLETED);
                }
            }
            return(successProcess);
        }