Ejemplo n.º 1
0
        /* UPDATE ZLASTSYNC set lastSync = "23/01/2020 4:49:41 AM"
         * where Mapping_ID not in (SELECT ID FROM ZMAPPING WHERE TYPE IN ("API") );
         * DELETE FROM ZQUEUE;
         */
        public static bool RunSQLLiteCmd(string token, Zmapping cmd)
        {
            using (var db = new ZudelloContext())
            {
                try
                {
                    //Exceute the custom command
                    db.Database.ExecuteSqlCommand(cmd.Body);
                    db.SaveChanges();

                    //Remove custom command from database FK
                    var lastSyncQuery = db.Zlastsync.Where(z => z.MappingId == cmd.Id).FirstOrDefault();
                    var mappingTbl    = db.Zmapping.Where(z => z.uuid == cmd.uuid);

                    foreach (Zmapping sqlQuery in mappingTbl)
                    {
                        //Dont need to remove as its never added into sync table
                        // db.Remove(lastSyncQuery);
                        // db.SaveChanges();
                        db.Remove(sqlQuery);
                        db.SaveChanges();
                        //Send delete request to Zudello to remove from mappings table
                        Console.WriteLine(ZudelloLogin.DeleteMapping(token, cmd.uuid));
                    }
                    return(true);
                }

                catch (Exception ex)
                {
                    return(false);
                }
            }
        }